StdGen does not generate 0
(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 `