StdGen does not generate 0
|Reported by:||novadenizen||Owned by:||ekmett|
|Type of failure:||Other||Test Case:|
|Related Tickets:||Differential Revisions:|
genRange for StdGen returns (0,2147483562). However, as far as I can tell, StdGen doesn't generate 0.
This code performs 200 billion iterations of next on a StdGen. I ran it and it output Nothing. The probability that no 0 was generated by chance is approximately e-200/2.147 =~ 10-40.
import System.Random import Data.Int find0 :: StdGen -> Int64 -> Maybe Int64 find0 g0 n0 = aux g0 n0 where aux _ 0 = Nothing aux g r = let (v,g') = next g in if v == 0 then Just (n0 - r + 1) else aux g' (r-1) main :: IO () main = print $ find0 (mkStdGen 1234) 200000000000
Change History (11)
comment:10 Changed 8 months ago by thomie
- Resolution set to fixed
- Status changed from upstream to closed