Skip to content

Commit 6c6bcb6

Browse files
committed
finish renaming of from_entropy to from_os_rng
1 parent 5734b55 commit 6c6bcb6

File tree

8 files changed

+47
-47
lines changed

8 files changed

+47
-47
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ compiler versions will be compatible. This is especially true of Rand's
9292
experimental `simd_support` feature.
9393

9494
Rand supports limited functionality in `no_std` mode (enabled via
95-
`default-features = false`). In this case, `OsRng` and `from_entropy` are
95+
`default-features = false`). In this case, `OsRng` and `from_os_rng` are
9696
unavailable (unless `getrandom` is enabled), large parts of `seq` are
9797
unavailable (unless `alloc` is enabled), and `thread_rng` and `random` are
9898
unavailable.

benches/distributions.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ macro_rules! distr_int {
3232
($fnn:ident, $ty:ty, $distr:expr) => {
3333
#[bench]
3434
fn $fnn(b: &mut Bencher) {
35-
let mut rng = Pcg64Mcg::from_entropy();
35+
let mut rng = Pcg64Mcg::from_os_rng();
3636
let distr = $distr;
3737

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

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

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

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

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

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

235235
b.iter(|| {
236236
let mut high = $high;
@@ -267,7 +267,7 @@ macro_rules! uniform_sample {
267267
($fnn:ident, $type:ident, $low:expr, $high:expr, $count:expr) => {
268268
#[bench]
269269
fn $fnn(b: &mut Bencher) {
270-
let mut rng = Pcg64Mcg::from_entropy();
270+
let mut rng = Pcg64Mcg::from_os_rng();
271271
let low = black_box($low);
272272
let high = black_box($high);
273273
b.iter(|| {
@@ -286,7 +286,7 @@ macro_rules! uniform_inclusive {
286286
($fnn:ident, $type:ident, $low:expr, $high:expr, $count:expr) => {
287287
#[bench]
288288
fn $fnn(b: &mut Bencher) {
289-
let mut rng = Pcg64Mcg::from_entropy();
289+
let mut rng = Pcg64Mcg::from_os_rng();
290290
let low = black_box($low);
291291
let high = black_box($high);
292292
b.iter(|| {
@@ -306,7 +306,7 @@ macro_rules! uniform_single {
306306
($fnn:ident, $type:ident, $low:expr, $high:expr, $count:expr) => {
307307
#[bench]
308308
fn $fnn(b: &mut Bencher) {
309-
let mut rng = Pcg64Mcg::from_entropy();
309+
let mut rng = Pcg64Mcg::from_os_rng();
310310
let low = black_box($low);
311311
let high = black_box($high);
312312
b.iter(|| {

benches/generators.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ macro_rules! gen_bytes {
4242
}
4343

4444
gen_bytes!(gen_bytes_step, StepRng::new(0, 1));
45-
gen_bytes!(gen_bytes_pcg32, Pcg32::from_entropy());
46-
gen_bytes!(gen_bytes_pcg64, Pcg64::from_entropy());
47-
gen_bytes!(gen_bytes_pcg64mcg, Pcg64Mcg::from_entropy());
48-
gen_bytes!(gen_bytes_pcg64dxsm, Pcg64Dxsm::from_entropy());
49-
gen_bytes!(gen_bytes_chacha8, ChaCha8Rng::from_entropy());
50-
gen_bytes!(gen_bytes_chacha12, ChaCha12Rng::from_entropy());
51-
gen_bytes!(gen_bytes_chacha20, ChaCha20Rng::from_entropy());
52-
gen_bytes!(gen_bytes_std, StdRng::from_entropy());
45+
gen_bytes!(gen_bytes_pcg32, Pcg32::from_os_rng());
46+
gen_bytes!(gen_bytes_pcg64, Pcg64::from_os_rng());
47+
gen_bytes!(gen_bytes_pcg64mcg, Pcg64Mcg::from_os_rng());
48+
gen_bytes!(gen_bytes_pcg64dxsm, Pcg64Dxsm::from_os_rng());
49+
gen_bytes!(gen_bytes_chacha8, ChaCha8Rng::from_os_rng());
50+
gen_bytes!(gen_bytes_chacha12, ChaCha12Rng::from_os_rng());
51+
gen_bytes!(gen_bytes_chacha20, ChaCha20Rng::from_os_rng());
52+
gen_bytes!(gen_bytes_std, StdRng::from_os_rng());
5353
#[cfg(feature = "small_rng")]
5454
gen_bytes!(gen_bytes_small, SmallRng::from_thread_rng());
5555
gen_bytes!(gen_bytes_os, UnwrapErr(OsRng));
@@ -73,28 +73,28 @@ macro_rules! gen_uint {
7373
}
7474

7575
gen_uint!(gen_u32_step, u32, StepRng::new(0, 1));
76-
gen_uint!(gen_u32_pcg32, u32, Pcg32::from_entropy());
77-
gen_uint!(gen_u32_pcg64, u32, Pcg64::from_entropy());
78-
gen_uint!(gen_u32_pcg64mcg, u32, Pcg64Mcg::from_entropy());
79-
gen_uint!(gen_u32_pcg64dxsm, u32, Pcg64Dxsm::from_entropy());
80-
gen_uint!(gen_u32_chacha8, u32, ChaCha8Rng::from_entropy());
81-
gen_uint!(gen_u32_chacha12, u32, ChaCha12Rng::from_entropy());
82-
gen_uint!(gen_u32_chacha20, u32, ChaCha20Rng::from_entropy());
83-
gen_uint!(gen_u32_std, u32, StdRng::from_entropy());
76+
gen_uint!(gen_u32_pcg32, u32, Pcg32::from_os_rng());
77+
gen_uint!(gen_u32_pcg64, u32, Pcg64::from_os_rng());
78+
gen_uint!(gen_u32_pcg64mcg, u32, Pcg64Mcg::from_os_rng());
79+
gen_uint!(gen_u32_pcg64dxsm, u32, Pcg64Dxsm::from_os_rng());
80+
gen_uint!(gen_u32_chacha8, u32, ChaCha8Rng::from_os_rng());
81+
gen_uint!(gen_u32_chacha12, u32, ChaCha12Rng::from_os_rng());
82+
gen_uint!(gen_u32_chacha20, u32, ChaCha20Rng::from_os_rng());
83+
gen_uint!(gen_u32_std, u32, StdRng::from_os_rng());
8484
#[cfg(feature = "small_rng")]
8585
gen_uint!(gen_u32_small, u32, SmallRng::from_thread_rng());
8686
gen_uint!(gen_u32_os, u32, UnwrapErr(OsRng));
8787
gen_uint!(gen_u32_thread, u32, thread_rng());
8888

8989
gen_uint!(gen_u64_step, u64, StepRng::new(0, 1));
90-
gen_uint!(gen_u64_pcg32, u64, Pcg32::from_entropy());
91-
gen_uint!(gen_u64_pcg64, u64, Pcg64::from_entropy());
92-
gen_uint!(gen_u64_pcg64mcg, u64, Pcg64Mcg::from_entropy());
93-
gen_uint!(gen_u64_pcg64dxsm, u64, Pcg64Dxsm::from_entropy());
94-
gen_uint!(gen_u64_chacha8, u64, ChaCha8Rng::from_entropy());
95-
gen_uint!(gen_u64_chacha12, u64, ChaCha12Rng::from_entropy());
96-
gen_uint!(gen_u64_chacha20, u64, ChaCha20Rng::from_entropy());
97-
gen_uint!(gen_u64_std, u64, StdRng::from_entropy());
90+
gen_uint!(gen_u64_pcg32, u64, Pcg32::from_os_rng());
91+
gen_uint!(gen_u64_pcg64, u64, Pcg64::from_os_rng());
92+
gen_uint!(gen_u64_pcg64mcg, u64, Pcg64Mcg::from_os_rng());
93+
gen_uint!(gen_u64_pcg64dxsm, u64, Pcg64Dxsm::from_os_rng());
94+
gen_uint!(gen_u64_chacha8, u64, ChaCha8Rng::from_os_rng());
95+
gen_uint!(gen_u64_chacha12, u64, ChaCha12Rng::from_os_rng());
96+
gen_uint!(gen_u64_chacha20, u64, ChaCha20Rng::from_os_rng());
97+
gen_uint!(gen_u64_std, u64, StdRng::from_os_rng());
9898
#[cfg(feature = "small_rng")]
9999
gen_uint!(gen_u64_small, u64, SmallRng::from_thread_rng());
100100
gen_uint!(gen_u64_os, u64, UnwrapErr(OsRng));
@@ -104,7 +104,7 @@ macro_rules! init_gen {
104104
($fnn:ident, $gen:ident) => {
105105
#[bench]
106106
fn $fnn(b: &mut Bencher) {
107-
let mut rng = Pcg32::from_entropy();
107+
let mut rng = Pcg32::from_os_rng();
108108
b.iter(|| {
109109
let r2 = $gen::from_rng(&mut rng);
110110
r2
@@ -126,7 +126,7 @@ macro_rules! reseeding_bytes {
126126
($fnn:ident, $thresh:expr) => {
127127
#[bench]
128128
fn $fnn(b: &mut Bencher) {
129-
let mut rng = ReseedingRng::new(ChaCha20Core::from_entropy(), $thresh * 1024, OsRng);
129+
let mut rng = ReseedingRng::new(ChaCha20Core::from_os_rng(), $thresh * 1024, OsRng);
130130
let mut buf = [0u8; RESEEDING_BYTES_LEN];
131131
b.iter(|| {
132132
for _ in 0..RESEEDING_BENCH_N {

rand_chacha/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Links:
3636
`rand_chacha` is `no_std` compatible when disabling default features; the `std`
3737
feature can be explicitly required to re-enable `std` support. Using `std`
3838
allows detection of CPU features and thus better optimisation. Using `std`
39-
also enables `getrandom` functionality, such as `ChaCha20Rng::from_entropy()`.
39+
also enables `getrandom` functionality, such as `ChaCha20Rng::from_os_rng()`.
4040

4141

4242
# License

rand_distr/benches/src/distributions.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ macro_rules! distr_int {
3030
$group.throughput(Throughput::Bytes(
3131
size_of::<$ty>() as u64 * RAND_BENCH_N));
3232
$group.bench_function($fnn, |c| {
33-
let mut rng = Pcg64Mcg::from_entropy();
33+
let mut rng = Pcg64Mcg::from_os_rng();
3434
let distr = $distr;
3535

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

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

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

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

rand_distr/tests/uniformity.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn unit_sphere() {
2323
let h = Histogram100::with_const_width(-1., 1.);
2424
let mut histograms = [h.clone(), h.clone(), h];
2525
let dist = rand_distr::UnitSphere;
26-
let mut rng = rand_pcg::Pcg32::from_entropy();
26+
let mut rng = rand_pcg::Pcg32::from_os_rng();
2727
for _ in 0..N_SAMPLES {
2828
let v: [f64; 3] = dist.sample(&mut rng);
2929
for i in 0..N_DIM {
@@ -51,7 +51,7 @@ fn unit_circle() {
5151
use core::f64::consts::PI;
5252
let mut h = Histogram100::with_const_width(-PI, PI);
5353
let dist = rand_distr::UnitCircle;
54-
let mut rng = rand_pcg::Pcg32::from_entropy();
54+
let mut rng = rand_pcg::Pcg32::from_os_rng();
5555
for _ in 0..N_SAMPLES {
5656
let v: [f64; 2] = dist.sample(&mut rng);
5757
h.add(v[0].atan2(v[1])).unwrap();

rand_pcg/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
//! use rand::{Rng, SeedableRng};
4848
//! use rand_pcg::Pcg64Mcg;
4949
//!
50-
//! let mut rng = Pcg64Mcg::from_entropy();
50+
//! let mut rng = Pcg64Mcg::from_os_rng();
5151
//! let x: f64 = rng.gen();
5252
//! ```
5353

src/rngs/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
//! - `from_seed` accepts a type specific to the PRNG
4343
//! - `from_rng` allows a PRNG to be seeded from any other RNG
4444
//! - `seed_from_u64` allows any PRNG to be seeded from a `u64` insecurely
45-
//! - `from_entropy` securely seeds a PRNG from fresh entropy
45+
//! - `from_os_rng` securely seeds a PRNG from system randomness source
4646
//!
4747
//! Use the [`rand_core`] crate when implementing your own RNGs.
4848
//!

0 commit comments

Comments
 (0)