rust-random / rand

A Rust library for random number generation.
https://crates.io/crates/rand
Other
1.68k stars 431 forks source link

Rename SmallRng::from_thread_rng to from_rand_rng #1531

Closed dhardy closed 5 days ago

dhardy commented 5 days ago

Summary

Title

Motivation

Function thread_rng was renamed to just rng. We can't call this method from_rng since that clashes with the SeedableRng method, so this seems like the next best choice (also aligning somewhat with the terminology we use in docs).

dhardy commented 5 days ago

So in benchmarks we're now doing stuff like this:

    bench(&mut g, "chacha20", ChaCha20Rng::from_os_rng());
    bench(&mut g, "std", StdRng::from_os_rng());
    bench(&mut g, "small", SmallRng::from_rand_rng());

The reason we don't have from_rand_rng everywhere is because SeedableRng is defined in rand_core and rand::rng is not available there.

This leads me to conclude that perhaps:

  1. We should remove SmallRng::from_rand_rng which is a special case, and use RNG::from_rng(&mut rand::rng()) instead
  2. We should merge rand_core back into rand so that we can add SeedableRng::from_rand_rng. Major caveat: rand will not be able to depend on externally-defined-RNGs like StdRng currently does.

Obviously, the first solution looks better. from_thread_rng was added in #1368 where the SeedableRng impl was dropped, but that has since been added back in.