GHC: Ticket Query
http://ghc.haskell.org/trac/ghc/query?status=closed&component=libraries%2Frandom&milestone=Not+GHC&group=resolution&order=priority
The Glasgow Haskell Compileren-USGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/query?status=closed&component=libraries%2Frandom&milestone=Not+GHC&group=resolution&order=priority
Trac 1.0.1
http://ghc.haskell.org/trac/ghc/ticket/4314
http://ghc.haskell.org/trac/ghc/ticket/4314#4314: Move 'split' from the 'RandomGen' class to a new 'SplittableGen' classTue, 14 Sep 2010 23:39:52 GMTTomMD<p>
The proposal is to:
</p>
<p>
1) Create the 'SplittableGen' class in System.Random:
class SplittableGen g where split :: g -> (g,g)
</p>
<p>
2) (Re)move the 'split' routine from RandomGen.
</p>
Resultshttp://ghc.haskell.org/trac/ghc/ticket/4314#changelog
http://ghc.haskell.org/trac/ghc/ticket/1120
http://ghc.haskell.org/trac/ghc/ticket/1120#1120: randomR is non-uniform for most rangesFri, 26 Jan 2007 14:29:37 GMTastrolabe<p>
If m < n, you can't convert a uniform random sample from [0,n-1]
to one from [0,m-1] using mod unless m|n. For example, if
m = n-1 then the getting 0 is twice as likely as getting anything
else. However, this scheme is what seems to be used in this function from
<a class="ext-link" href="http://darcs.haskell.org/ghc-6.6/packages/base/System/Random.hs"><span class="icon"></span>http://darcs.haskell.org/ghc-6.6/packages/base/System/Random.hs</a>
</p>
<pre class="wiki">randomIvalInteger :: (RandomGen g, Num a) => (Integer, Integer) -> g -> (a, g)
randomIvalInteger (l,h) rng
| l > h = randomIvalInteger (h,l) rng
| otherwise = case (f n 1 rng) of (v, rng') -> (fromInteger (l + v `mod` k), rng')
where
k = h - l + 1
b = 2147483561
n = iLogBase b k
f 0 acc g = (acc, g)
f n acc g =
let
(x,g') = next g
in
f (n-1) (fromIntegral x + acc * b) g'
</pre><p>
One possible fix is to repeatedly sample from [0,n-1] until you get
a value that is in [0,floor(n/m)*m-1]. This would work practically, but
is not gauranteed to terminate. You should, in my opinion, at least try
a few samples before accepting one that isn't in this range.
</p>
Resultshttp://ghc.haskell.org/trac/ghc/ticket/1120#changelog
http://ghc.haskell.org/trac/ghc/ticket/4315
http://ghc.haskell.org/trac/ghc/ticket/4315#4315: Generalize the 'RandomGen' and 'Random' classesTue, 14 Sep 2010 23:51:05 GMTTomMD<p>
RandomGen and Random classes assume generators produce Int values. This is non-ideal as many high speed generators produce special values (ex: doubles) or generic values (bit streams / bytestrings) that can be converted directly to my types easier than coercing to Int then to an 'a' via the Random class.
</p>
<p>
The proposal is to change the classes from/to:
</p>
<pre class="wiki"> class RandomGen g where
-->
class RandomGen g v | g -> v where
</pre><p>
and
</p>
<pre class="wiki"> class Random a where
-->
class Random a v where
</pre><p>
And make needed changes to the classes instances that follow from these.
</p>
Resultshttp://ghc.haskell.org/trac/ghc/ticket/4315#changelog