Skip to content

from_rng and value-stability #572

@dhardy

Description

@dhardy

From the doc for SeedableRng::from_rng:

    /// Usage of this method is not recommended when reproducibility is required
    /// since implementing PRNGs are not required to fix Endianness and are
    /// allowed to modify implementations in new releases.

The rationale of not making this method value-stable is to allow more room for optimisation and potentially entropy:

  • no need to worry about Endianness
  • no value-stability means the method is open to optimisation in the future
  • RNGs with large internal state space (Hc128Rng, ISAAC) can fill the entire state directly instead of using key expansion — except we never implemented this for Hc128Rng, and ISAAC still uses the same routines to scramble the key in case it is poor quality

The rationale against this:

  • it is natural to want to write let mut my_new_rng = MyRng::from_rng(master_rng);, but we have to tell people not to do this if they want value-stability
  • directly filling the internal state space is not really an advantage for entropy since CryptoRngs already use sufficiently large keys, and adding more entropy is irrelevant relative to the strengths of the algorithm and available computational power (256 bits already being sufficient, unless we quantum computing requires major changes to cryptography in the future)
  • directly filling the internal state space is not a performance advantage when we must use scrambling routines anyway
  • the other rationales for are trivial

So it seems sensible to change this. I'd like @pitdicker's input since he was part of the current design.

Making this value-stable in a future version of rand_core is not a breaking change in any way, though users should not be able to count on value-stability until their dependencies depend on the new rand_core version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-questionParticipation: opinions wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions