Skip to content

add SeedableRng::fork methods#17

Merged
newpavlov merged 1 commit intorust-random:masterfrom
baloo:baloo/seedablerng/fork
Nov 6, 2025
Merged

add SeedableRng::fork methods#17
newpavlov merged 1 commit intorust-random:masterfrom
baloo:baloo/seedablerng/fork

Conversation

@baloo
Copy link
Contributor

@baloo baloo commented Nov 5, 2025

  • Added a CHANGELOG.md entry

Summary

This provide a fork method to "clone" an Rng.

Motivation

This is handy to initialize an Rng that needs to be given to another thread for example.

rand_chacha used to provide a clonable Chacha20Rng (arguably incorrect). chacha20::Chacha20Rng is not clonable. But it's convenient to fork RNGs when initializing a thread or whatnot.

Details

This provide a fork method to "clone" an Rng. This is handy to
initialize an Rng that needs to be given to another thread for example.
@newpavlov newpavlov merged commit 4e856da into rust-random:master Nov 6, 2025
13 checks passed
@baloo baloo deleted the baloo/seedablerng/fork branch November 6, 2025 03:54
@dhardy
Copy link
Member

dhardy commented Nov 28, 2025

Is this feature purely for convenience / user experience or also intended to allow implementers to provide their own implementations?

@baloo
Copy link
Contributor Author

baloo commented Nov 28, 2025

Convenience and readability.

@tarcieri
Copy link
Contributor

I think it’s nice to have something to point at as a secure and convenient replacement for Clone

@baloo
Copy link
Contributor Author

baloo commented Nov 29, 2025

I mean, there is nothing in the current API stopping us from using from_rng and duplicate the body (and this is what we did in crypto-primes). But I believe fork is more readable as it carry the intent.

@dhardy
Copy link
Member

dhardy commented Nov 29, 2025

It is an acceptable addition (considering the Sized bound on the trait).

takumi-earth pushed a commit to earthlings-dev/rand_core that referenced this pull request Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants