Stunning biased random number formation with random

I assume something is wrong here:

ghci> take 10 $ randomRs (1,6) (mkStdGen 2)
[6,4,1,5,4,2,2,2,2,3]
ghci> take 10 $ randomRs (1,6) (mkStdGen 3)
[6,4,5,4,4,2,1,1,5,1]
ghci> take 10 $ randomRs (1,6) (mkStdGen 5)
[6,2,2,1,3,2,5,1,5,4]
ghci> take 10 $ randomRs (1,6) (mkStdGen 7)
[6,1,4,5,3,2,3,6,6,6]
ghci> take 10 $ randomRs (1,6) (mkStdGen 11)
[6,4,4,6,1,2,6,5,6,5]

Why is the first random number always “random” 6 ...?

Same picture with "n" for letters a through z:

ghci> take 10 $ randomRs ('a','z') (mkStdGen 13)
"nnofwbxbtw"
ghci> take 10 $ randomRs ('a','z') (mkStdGen 17)
"novkmtfugl"
ghci> take 10 $ randomRs ('a','z') (mkStdGen 19)
"nhurafjvey"

I stumbled upon this while working through LYAHFGG (chapter 9 by chance) and really don't understand it. I would not expect any pattern between seeds.

+4
source share
2 answers

System.Random.StdGen- This is a terrible generator that had to be replaced for a long time. There are even quickcheck properties that are obviously false, which still pass after thousands of checks due to poor quality StdGen- and this is done with good sowing.

, . tf-random StdGen, DRBG mersenne-random-pure64 .

+6

, , , maxBound :: Int. , . , randomR ", ", WRT - .

, , - . - .

+3

All Articles