Skip to content

mkStdGen should take a Word64 instead of an Int #141

Description

@ramirez7

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?)

Activity

  1. Shimuuar commented on Aug 23, 2023

    @Shimuuar
    Contributor

    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

  2. lehins commented on Aug 23, 2023

    @lehins
    Contributor

    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

  3. added 2 commits that reference this issue on Nov 26, 2023
    3a9557a
    207fe49
  4. ramirez7 commented on Nov 27, 2023

    @ramirez7
    Author

    Great to see this closed! Quality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions