haskell / random

Random number library
Other
53 stars 50 forks source link

mkStdGen should take a Word64 instead of an Int #141

Closed ramirez7 closed 10 months ago

ramirez7 commented 1 year ago

I want to deterministically seed with mkStdGen based on some unique bits I have (some UUID). I noticed that mkStdGen take Int and then fromIntegrals it to a Word64, which splitmix actually uses.

Why not just expose the Word64 seeding function directly? I'd like to very explicitly provide 64 bits.

For now, I can either just do my stuff in Word32/Word64 and fromIntegral myself. Or I can do bit stuff and do split binary search.

If backwards compat is the issue, I suggest mkStdGenW64 :: Word64 -> StdGen (maybe I'll provide a PR myself?)

Shimuuar commented 1 year ago

This is because mkStdGen precedes use of splitmix (since 1.2). But you can use generator from splitmix directly. And it exposes construction from Word64

lehins commented 1 year ago

Why not just expose the Word64 seeding function directly? ... If backwards compat is the issue, I suggest mkStdGenW64 :: Word64 -> StdGen (maybe I'll provide a PR myself?)

Yeah, we are not about to break compatibility of a function that is like 3 decades old. However, I do agree that providing mkStdGen64 :: Word64 -> StdGen would be a good idea. It would be great if you could submit a PR? Side note, I don't think suffix W is necessary)

I'd like to very explicitly provide 64 bits.

I am sure you know this, but just to make sure we are on the same page. By casting Int to Word64 you are not loosing any bits, unless you are on a 32bit machine

ramirez7 commented 10 months ago

Great to see this closed! Quality.