Skip to content

To provide (or not) specific PRNGs? #58

@arthurprs

Description

@arthurprs

On rust-lang/rfcs#2106 (comment) I argued that rand should not provide any specific/named rngs (so no ChaChaRng, XoroShiro, etc.) but instead provide a very small set of generators (OsRng, StdRng, etc.) in addition to the trait machinery, etc..

Consider just WeakRng for example (StdRng might be enough moving forward), there were almost half a dozen proposals to improve it. One can argue that the initial choice wasn't the best but it's bound to happen again no matter the upfront effort.

In the event that rand keeps providing specific Rngs, proposals with merits will eventually come and the crate will be tied to the older variant until the next major version (w/ a higher friction upgrade). Until that happens the maintainers have a few choices:

  1. Reject the PR (for reason X, even if its a win) and ask the author to push it to crates.io instead
  2. Accept the PR adding generator G to rand
  3. Accept the PR adding generator G to rand and mark the other(s) deprecated

Note that 2 and 3 are likely duplicating something from crates.io, but with a blessing.

Advantages

  • rand provide easy to reason generator(s) to satisfy the bulk of the users
  • rand provides low-friction upgrades and keeps the optimal-ish algorithms readily available
  • rand will not accumulate and/or deprecate specific algorithms throughout time
  • Specific rand Rng names won't bleed out to the world, like in forum posts, stackoverflow, etc..

Disadvantages

  • There will be no blessed specific Rng implementations
  • Major versions bumps are required, whereas providing specific implementations can get away with new Rngs and give or take a deprecation warning.

Non concerns

  • Reproducibility/_Seed_ability can still be guaranteed across major versions.
  • If the user needs a specific Rng it should reach out to a crate (crates.io raison d'être)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions