#5278: System.Random.randomIvalInteger makes invalid assumptions about RandomGen
---------------------------------+------------------------------------------
Reporter: rrnewton | Owner: rrnewton
Type: bug | Status: new
Priority: normal | Component: libraries/random
Version: 7.0.3 | Keywords: incorrect assumption
Testcase: | Blockedby:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: Incorrect result at runtime
---------------------------------+------------------------------------------
The existing API for `System.Random.RandomGen` allows a random number
generator (RNG) to produce Ints within an arbitrary range specified by
`genRange`.
For example, the following `RandomGen` produces only zeros and ones, but
should be legitimate:
{{{
import System.Random
data BinRNG = BinRNG StdGen
instance RandomGen BinRNG where
next (BinRNG g) = (x `mod` 2, BinRNG g')
where (x,g') = next g
split (BinRNG g) = (BinRNG g1, BinRNG g2)
where (g1,g2) = split g
genRange _ = (0,1)
ls :: [Int]
ls = randoms (BinRNG$ mkStdGen 38388)
main = print $ take 20 ls
}}}
But `System.Random.randomIvalInteger` makes invalid assumptions about the
amount of randomness produced by `next`. (Specifically, assuming that it
creates the same amount as `StdGen`.) Thus, the above program will create
an output with only a couple of unique ints (rather than 2^64).
For example:
{{{
[4611734781337924537,4611734781337924537,-9223323645458902796,
-9223323645458902797,4611734783485408099,4611734783485408098,
-9223323645458902796,-9223323647606386357,4611734781337924538,
-9223323645458902796,-9223323645458902797,
-9223323647606386357,4611734783485408098,4611734783485408098,
-9223323647606386357,4611734781337924538,4611734781337924537,
-9223323645458902796,4611734783485408099,4611734781337924538]
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5278>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs