haskell / mwc-random

A very fast Haskell library for generating high quality pseudo-random numbers.
http://hackage.haskell.org/package/mwc-random
BSD 2-Clause "Simplified" License
54 stars 25 forks source link

0.15 stopped generating random numbers #75

Closed glguy closed 3 years ago

glguy commented 3 years ago
seed <- createSystemSeed
print (runST (do gen <- restore seed; uniformR (0,99999::Int) gen))

This always prints 0 for me in 0.15 but it used to work in 0.14. Perhaps restore is broken? (my actual use-case saves the generator afterward back to a new seed)

Shimuuar commented 3 years ago

Thanks for the report! It looks like that uniformR got somehow broken. Following program only prints 0-s.

step = do
  gen  <- createSystemRandom
  replicateM_ 10 $ print =<< uniformR (0,6::Int) gen
Shimuuar commented 3 years ago

Turns out it's CPP problem. Some include was dropped accidentally. WORD_SIZE_IN_BITS is no longer is CPP macro and #if WORD_SIZE_IN_BITS < 64 evaluated as true so uniform for Int generates only 32 bits values in 64 bit platforms breaking uniformR along the way.

I would hope that it should be compile error.

Shimuuar commented 3 years ago

c195ca081d08d2a838caf63ec1c0ec6b4830c1e9 should fix this problem I believe. I'll make a release tomorrow

Shimuuar commented 3 years ago

0.15.0.1 is on hackage