Skip to content

Commit

Permalink
finish renaming of from_entropy to from_os_rng
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Apr 20, 2024
1 parent 5734b55 commit 6c6bcb6
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ compiler versions will be compatible. This is especially true of Rand's
experimental `simd_support` feature.

Rand supports limited functionality in `no_std` mode (enabled via
`default-features = false`). In this case, `OsRng` and `from_entropy` are
`default-features = false`). In this case, `OsRng` and `from_os_rng` are
unavailable (unless `getrandom` is enabled), large parts of `seq` are
unavailable (unless `alloc` is enabled), and `thread_rng` and `random` are
unavailable.
Expand Down
20 changes: 10 additions & 10 deletions benches/distributions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ macro_rules! distr_int {
($fnn:ident, $ty:ty, $distr:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let distr = $distr;

b.iter(|| {
Expand All @@ -52,7 +52,7 @@ macro_rules! distr_nz_int {
($fnn:ident, $tynz:ty, $ty:ty, $distr:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let distr = $distr;

b.iter(|| {
Expand All @@ -72,7 +72,7 @@ macro_rules! distr_float {
($fnn:ident, $ty:ty, $distr:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let distr = $distr;

b.iter(|| {
Expand All @@ -92,7 +92,7 @@ macro_rules! distr_duration {
($fnn:ident, $distr:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let distr = $distr;

b.iter(|| {
Expand All @@ -114,7 +114,7 @@ macro_rules! distr {
($fnn:ident, $ty:ty, $distr:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let distr = $distr;

b.iter(|| {
Expand Down Expand Up @@ -191,7 +191,7 @@ macro_rules! gen_range_int {
($fnn:ident, $ty:ident, $low:expr, $high:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();

b.iter(|| {
let mut high = $high;
Expand Down Expand Up @@ -230,7 +230,7 @@ macro_rules! gen_range_float {
($fnn:ident, $ty:ident, $low:expr, $high:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();

b.iter(|| {
let mut high = $high;
Expand Down Expand Up @@ -267,7 +267,7 @@ macro_rules! uniform_sample {
($fnn:ident, $type:ident, $low:expr, $high:expr, $count:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let low = black_box($low);
let high = black_box($high);
b.iter(|| {
Expand All @@ -286,7 +286,7 @@ macro_rules! uniform_inclusive {
($fnn:ident, $type:ident, $low:expr, $high:expr, $count:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let low = black_box($low);
let high = black_box($high);
b.iter(|| {
Expand All @@ -306,7 +306,7 @@ macro_rules! uniform_single {
($fnn:ident, $type:ident, $low:expr, $high:expr, $count:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let low = black_box($low);
let high = black_box($high);
b.iter(|| {
Expand Down
52 changes: 26 additions & 26 deletions benches/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ macro_rules! gen_bytes {
}

gen_bytes!(gen_bytes_step, StepRng::new(0, 1));
gen_bytes!(gen_bytes_pcg32, Pcg32::from_entropy());
gen_bytes!(gen_bytes_pcg64, Pcg64::from_entropy());
gen_bytes!(gen_bytes_pcg64mcg, Pcg64Mcg::from_entropy());
gen_bytes!(gen_bytes_pcg64dxsm, Pcg64Dxsm::from_entropy());
gen_bytes!(gen_bytes_chacha8, ChaCha8Rng::from_entropy());
gen_bytes!(gen_bytes_chacha12, ChaCha12Rng::from_entropy());
gen_bytes!(gen_bytes_chacha20, ChaCha20Rng::from_entropy());
gen_bytes!(gen_bytes_std, StdRng::from_entropy());
gen_bytes!(gen_bytes_pcg32, Pcg32::from_os_rng());
gen_bytes!(gen_bytes_pcg64, Pcg64::from_os_rng());
gen_bytes!(gen_bytes_pcg64mcg, Pcg64Mcg::from_os_rng());
gen_bytes!(gen_bytes_pcg64dxsm, Pcg64Dxsm::from_os_rng());
gen_bytes!(gen_bytes_chacha8, ChaCha8Rng::from_os_rng());
gen_bytes!(gen_bytes_chacha12, ChaCha12Rng::from_os_rng());
gen_bytes!(gen_bytes_chacha20, ChaCha20Rng::from_os_rng());
gen_bytes!(gen_bytes_std, StdRng::from_os_rng());
#[cfg(feature = "small_rng")]
gen_bytes!(gen_bytes_small, SmallRng::from_thread_rng());
gen_bytes!(gen_bytes_os, UnwrapErr(OsRng));
Expand All @@ -73,28 +73,28 @@ macro_rules! gen_uint {
}

gen_uint!(gen_u32_step, u32, StepRng::new(0, 1));
gen_uint!(gen_u32_pcg32, u32, Pcg32::from_entropy());
gen_uint!(gen_u32_pcg64, u32, Pcg64::from_entropy());
gen_uint!(gen_u32_pcg64mcg, u32, Pcg64Mcg::from_entropy());
gen_uint!(gen_u32_pcg64dxsm, u32, Pcg64Dxsm::from_entropy());
gen_uint!(gen_u32_chacha8, u32, ChaCha8Rng::from_entropy());
gen_uint!(gen_u32_chacha12, u32, ChaCha12Rng::from_entropy());
gen_uint!(gen_u32_chacha20, u32, ChaCha20Rng::from_entropy());
gen_uint!(gen_u32_std, u32, StdRng::from_entropy());
gen_uint!(gen_u32_pcg32, u32, Pcg32::from_os_rng());
gen_uint!(gen_u32_pcg64, u32, Pcg64::from_os_rng());
gen_uint!(gen_u32_pcg64mcg, u32, Pcg64Mcg::from_os_rng());
gen_uint!(gen_u32_pcg64dxsm, u32, Pcg64Dxsm::from_os_rng());
gen_uint!(gen_u32_chacha8, u32, ChaCha8Rng::from_os_rng());
gen_uint!(gen_u32_chacha12, u32, ChaCha12Rng::from_os_rng());
gen_uint!(gen_u32_chacha20, u32, ChaCha20Rng::from_os_rng());
gen_uint!(gen_u32_std, u32, StdRng::from_os_rng());
#[cfg(feature = "small_rng")]
gen_uint!(gen_u32_small, u32, SmallRng::from_thread_rng());
gen_uint!(gen_u32_os, u32, UnwrapErr(OsRng));
gen_uint!(gen_u32_thread, u32, thread_rng());

gen_uint!(gen_u64_step, u64, StepRng::new(0, 1));
gen_uint!(gen_u64_pcg32, u64, Pcg32::from_entropy());
gen_uint!(gen_u64_pcg64, u64, Pcg64::from_entropy());
gen_uint!(gen_u64_pcg64mcg, u64, Pcg64Mcg::from_entropy());
gen_uint!(gen_u64_pcg64dxsm, u64, Pcg64Dxsm::from_entropy());
gen_uint!(gen_u64_chacha8, u64, ChaCha8Rng::from_entropy());
gen_uint!(gen_u64_chacha12, u64, ChaCha12Rng::from_entropy());
gen_uint!(gen_u64_chacha20, u64, ChaCha20Rng::from_entropy());
gen_uint!(gen_u64_std, u64, StdRng::from_entropy());
gen_uint!(gen_u64_pcg32, u64, Pcg32::from_os_rng());
gen_uint!(gen_u64_pcg64, u64, Pcg64::from_os_rng());
gen_uint!(gen_u64_pcg64mcg, u64, Pcg64Mcg::from_os_rng());
gen_uint!(gen_u64_pcg64dxsm, u64, Pcg64Dxsm::from_os_rng());
gen_uint!(gen_u64_chacha8, u64, ChaCha8Rng::from_os_rng());
gen_uint!(gen_u64_chacha12, u64, ChaCha12Rng::from_os_rng());
gen_uint!(gen_u64_chacha20, u64, ChaCha20Rng::from_os_rng());
gen_uint!(gen_u64_std, u64, StdRng::from_os_rng());
#[cfg(feature = "small_rng")]
gen_uint!(gen_u64_small, u64, SmallRng::from_thread_rng());
gen_uint!(gen_u64_os, u64, UnwrapErr(OsRng));
Expand All @@ -104,7 +104,7 @@ macro_rules! init_gen {
($fnn:ident, $gen:ident) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = Pcg32::from_entropy();
let mut rng = Pcg32::from_os_rng();
b.iter(|| {
let r2 = $gen::from_rng(&mut rng);
r2
Expand All @@ -126,7 +126,7 @@ macro_rules! reseeding_bytes {
($fnn:ident, $thresh:expr) => {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = ReseedingRng::new(ChaCha20Core::from_entropy(), $thresh * 1024, OsRng);
let mut rng = ReseedingRng::new(ChaCha20Core::from_os_rng(), $thresh * 1024, OsRng);
let mut buf = [0u8; RESEEDING_BYTES_LEN];
b.iter(|| {
for _ in 0..RESEEDING_BENCH_N {
Expand Down
2 changes: 1 addition & 1 deletion rand_chacha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Links:
`rand_chacha` is `no_std` compatible when disabling default features; the `std`
feature can be explicitly required to re-enable `std` support. Using `std`
allows detection of CPU features and thus better optimisation. Using `std`
also enables `getrandom` functionality, such as `ChaCha20Rng::from_entropy()`.
also enables `getrandom` functionality, such as `ChaCha20Rng::from_os_rng()`.


# License
Expand Down
10 changes: 5 additions & 5 deletions rand_distr/benches/src/distributions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ macro_rules! distr_int {
$group.throughput(Throughput::Bytes(
size_of::<$ty>() as u64 * RAND_BENCH_N));
$group.bench_function($fnn, |c| {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let distr = $distr;

c.iter(|| {
Expand All @@ -50,7 +50,7 @@ macro_rules! distr_float {
$group.throughput(Throughput::Bytes(
size_of::<$ty>() as u64 * RAND_BENCH_N));
$group.bench_function($fnn, |c| {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let distr = $distr;

c.iter(|| {
Expand All @@ -70,7 +70,7 @@ macro_rules! distr {
$group.throughput(Throughput::Bytes(
size_of::<$ty>() as u64 * RAND_BENCH_N));
$group.bench_function($fnn, |c| {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let distr = $distr;

c.iter(|| {
Expand All @@ -90,7 +90,7 @@ macro_rules! distr_arr {
$group.throughput(Throughput::Bytes(
size_of::<$ty>() as u64 * RAND_BENCH_N));
$group.bench_function($fnn, |c| {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let distr = $distr;

c.iter(|| {
Expand Down Expand Up @@ -127,7 +127,7 @@ fn bench(c: &mut Criterion<CyclesPerByte>) {
distr_float!(g, "log_normal", f64, LogNormal::new(-1.23, 4.56).unwrap());
g.throughput(Throughput::Bytes(size_of::<f64>() as u64 * RAND_BENCH_N));
g.bench_function("iter", |c| {
let mut rng = Pcg64Mcg::from_entropy();
let mut rng = Pcg64Mcg::from_os_rng();
let distr = Normal::new(-2.71828, 3.14159).unwrap();
let mut iter = distr.sample_iter(&mut rng);

Expand Down
4 changes: 2 additions & 2 deletions rand_distr/tests/uniformity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn unit_sphere() {
let h = Histogram100::with_const_width(-1., 1.);
let mut histograms = [h.clone(), h.clone(), h];
let dist = rand_distr::UnitSphere;
let mut rng = rand_pcg::Pcg32::from_entropy();
let mut rng = rand_pcg::Pcg32::from_os_rng();
for _ in 0..N_SAMPLES {
let v: [f64; 3] = dist.sample(&mut rng);
for i in 0..N_DIM {
Expand Down Expand Up @@ -51,7 +51,7 @@ fn unit_circle() {
use core::f64::consts::PI;
let mut h = Histogram100::with_const_width(-PI, PI);
let dist = rand_distr::UnitCircle;
let mut rng = rand_pcg::Pcg32::from_entropy();
let mut rng = rand_pcg::Pcg32::from_os_rng();
for _ in 0..N_SAMPLES {
let v: [f64; 2] = dist.sample(&mut rng);
h.add(v[0].atan2(v[1])).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion rand_pcg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
//! use rand::{Rng, SeedableRng};
//! use rand_pcg::Pcg64Mcg;
//!
//! let mut rng = Pcg64Mcg::from_entropy();
//! let mut rng = Pcg64Mcg::from_os_rng();
//! let x: f64 = rng.gen();
//! ```

Expand Down
2 changes: 1 addition & 1 deletion src/rngs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
//! - `from_seed` accepts a type specific to the PRNG
//! - `from_rng` allows a PRNG to be seeded from any other RNG
//! - `seed_from_u64` allows any PRNG to be seeded from a `u64` insecurely
//! - `from_entropy` securely seeds a PRNG from fresh entropy
//! - `from_os_rng` securely seeds a PRNG from system randomness source
//!
//! Use the [`rand_core`] crate when implementing your own RNGs.
//!
Expand Down

0 comments on commit 6c6bcb6

Please sign in to comment.