You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On Linux I get a random-looking sequence, but on Windows I get big chunks of the same number repeated.
I think the problem is in the instance of MonadRandom:
instance MonadRandom IO where
getRandomPrim = withSystemRandom . (flip getRandomPrimFrom :: Prim t -> Gen RealWorld -> IO t)
This seems to call withSystemRandom for every random number, which reseeds the generator, and on Windows the current time is used as the seed, so every call within the same second gets the same result. (The documentation for withSystemRandom says that it should only be called once per thread or so [https://github.com/bos/mwc-random/blob/master/System/Random/MWC.hs#L423].)
The text was updated successfully, but these errors were encountered:
Very interesting. It will take me some time before I can look at this. I trust you have found a workaround for what you want to do? If not let me know and I can make some suggestions.
Yes, I've worked around it by creating a PureMT explicitly, putting it in an IORef, passing the IORef where needed and using sampleFrom directly. The other way might have been a bit neater, but it's not a big problem. I was definitely surprised by the odd behaviour, though!
Hello,
This test program works well on Linux but not on Windows. I am using the library the right way?
On Linux I get a random-looking sequence, but on Windows I get big chunks of the same number repeated.
I think the problem is in the instance of MonadRandom:
This seems to call
withSystemRandom
for every random number, which reseeds the generator, and on Windows the current time is used as the seed, so every call within the same second gets the same result. (The documentation forwithSystemRandom
says that it should only be called once per thread or so [https://github.com/bos/mwc-random/blob/master/System/Random/MWC.hs#L423].)The text was updated successfully, but these errors were encountered: