@@ -9,7 +9,7 @@ const BYTES_LEN: usize = 1024;
9
9
use std:: mem:: size_of;
10
10
use test:: { black_box, Bencher } ;
11
11
12
- use rand:: { RngCore , Rng , SeedableRng , NewRng } ;
12
+ use rand:: { RngCore , Rng , SeedableRng , FromEntropy } ;
13
13
use rand:: { StdRng , SmallRng , OsRng , EntropyRng , ReseedingRng } ;
14
14
use rand:: prng:: { XorShiftRng , Hc128Rng , IsaacRng , Isaac64Rng , ChaChaRng } ;
15
15
use rand:: prng:: hc128:: Hc128Core ;
@@ -33,12 +33,12 @@ macro_rules! gen_bytes {
33
33
}
34
34
}
35
35
36
- gen_bytes ! ( gen_bytes_xorshift, XorShiftRng :: new ( ) ) ;
37
- gen_bytes ! ( gen_bytes_hc128, Hc128Rng :: new ( ) ) ;
38
- gen_bytes ! ( gen_bytes_isaac, IsaacRng :: new ( ) ) ;
39
- gen_bytes ! ( gen_bytes_isaac64, Isaac64Rng :: new ( ) ) ;
40
- gen_bytes ! ( gen_bytes_std, StdRng :: new ( ) ) ;
41
- gen_bytes ! ( gen_bytes_small, SmallRng :: new ( ) ) ;
36
+ gen_bytes ! ( gen_bytes_xorshift, XorShiftRng :: from_entropy ( ) ) ;
37
+ gen_bytes ! ( gen_bytes_hc128, Hc128Rng :: from_entropy ( ) ) ;
38
+ gen_bytes ! ( gen_bytes_isaac, IsaacRng :: from_entropy ( ) ) ;
39
+ gen_bytes ! ( gen_bytes_isaac64, Isaac64Rng :: from_entropy ( ) ) ;
40
+ gen_bytes ! ( gen_bytes_std, StdRng :: from_entropy ( ) ) ;
41
+ gen_bytes ! ( gen_bytes_small, SmallRng :: from_entropy ( ) ) ;
42
42
gen_bytes ! ( gen_bytes_os, OsRng :: new( ) . unwrap( ) ) ;
43
43
44
44
macro_rules! gen_uint {
@@ -58,20 +58,20 @@ macro_rules! gen_uint {
58
58
}
59
59
}
60
60
61
- gen_uint ! ( gen_u32_xorshift, u32 , XorShiftRng :: new ( ) ) ;
62
- gen_uint ! ( gen_u32_hc128, u32 , Hc128Rng :: new ( ) ) ;
63
- gen_uint ! ( gen_u32_isaac, u32 , IsaacRng :: new ( ) ) ;
64
- gen_uint ! ( gen_u32_isaac64, u32 , Isaac64Rng :: new ( ) ) ;
65
- gen_uint ! ( gen_u32_std, u32 , StdRng :: new ( ) ) ;
66
- gen_uint ! ( gen_u32_small, u32 , SmallRng :: new ( ) ) ;
61
+ gen_uint ! ( gen_u32_xorshift, u32 , XorShiftRng :: from_entropy ( ) ) ;
62
+ gen_uint ! ( gen_u32_hc128, u32 , Hc128Rng :: from_entropy ( ) ) ;
63
+ gen_uint ! ( gen_u32_isaac, u32 , IsaacRng :: from_entropy ( ) ) ;
64
+ gen_uint ! ( gen_u32_isaac64, u32 , Isaac64Rng :: from_entropy ( ) ) ;
65
+ gen_uint ! ( gen_u32_std, u32 , StdRng :: from_entropy ( ) ) ;
66
+ gen_uint ! ( gen_u32_small, u32 , SmallRng :: from_entropy ( ) ) ;
67
67
gen_uint ! ( gen_u32_os, u32 , OsRng :: new( ) . unwrap( ) ) ;
68
68
69
- gen_uint ! ( gen_u64_xorshift, u64 , XorShiftRng :: new ( ) ) ;
70
- gen_uint ! ( gen_u64_hc128, u64 , Hc128Rng :: new ( ) ) ;
71
- gen_uint ! ( gen_u64_isaac, u64 , IsaacRng :: new ( ) ) ;
72
- gen_uint ! ( gen_u64_isaac64, u64 , Isaac64Rng :: new ( ) ) ;
73
- gen_uint ! ( gen_u64_std, u64 , StdRng :: new ( ) ) ;
74
- gen_uint ! ( gen_u64_small, u64 , SmallRng :: new ( ) ) ;
69
+ gen_uint ! ( gen_u64_xorshift, u64 , XorShiftRng :: from_entropy ( ) ) ;
70
+ gen_uint ! ( gen_u64_hc128, u64 , Hc128Rng :: from_entropy ( ) ) ;
71
+ gen_uint ! ( gen_u64_isaac, u64 , IsaacRng :: from_entropy ( ) ) ;
72
+ gen_uint ! ( gen_u64_isaac64, u64 , Isaac64Rng :: from_entropy ( ) ) ;
73
+ gen_uint ! ( gen_u64_std, u64 , StdRng :: from_entropy ( ) ) ;
74
+ gen_uint ! ( gen_u64_small, u64 , SmallRng :: from_entropy ( ) ) ;
75
75
gen_uint ! ( gen_u64_os, u64 , OsRng :: new( ) . unwrap( ) ) ;
76
76
77
77
// Do not test JitterRng like the others by running it RAND_BENCH_N times per,
@@ -89,7 +89,7 @@ macro_rules! init_gen {
89
89
( $fnn: ident, $gen: ident) => {
90
90
#[ bench]
91
91
fn $fnn( b: & mut Bencher ) {
92
- let mut rng = XorShiftRng :: new ( ) ;
92
+ let mut rng = XorShiftRng :: from_entropy ( ) ;
93
93
b. iter( || {
94
94
let r2 = $gen:: from_rng( & mut rng) . unwrap( ) ;
95
95
black_box( r2) ;
@@ -115,7 +115,7 @@ macro_rules! chacha_rounds {
115
115
( $fn1: ident, $fn2: ident, $fn3: ident, $rounds: expr) => {
116
116
#[ bench]
117
117
fn $fn1( b: & mut Bencher ) {
118
- let mut rng = ChaChaRng :: new ( ) ;
118
+ let mut rng = ChaChaRng :: from_entropy ( ) ;
119
119
rng. set_rounds( $rounds) ;
120
120
let mut buf = [ 0u8 ; BYTES_LEN ] ;
121
121
b. iter( || {
@@ -129,7 +129,7 @@ macro_rules! chacha_rounds {
129
129
130
130
#[ bench]
131
131
fn $fn2( b: & mut Bencher ) {
132
- let mut rng = ChaChaRng :: new ( ) ;
132
+ let mut rng = ChaChaRng :: from_entropy ( ) ;
133
133
rng. set_rounds( $rounds) ;
134
134
b. iter( || {
135
135
let mut accum: u32 = 0 ;
@@ -143,7 +143,7 @@ macro_rules! chacha_rounds {
143
143
144
144
#[ bench]
145
145
fn $fn3( b: & mut Bencher ) {
146
- let mut rng = ChaChaRng :: new ( ) ;
146
+ let mut rng = ChaChaRng :: from_entropy ( ) ;
147
147
rng. set_rounds( $rounds) ;
148
148
b. iter( || {
149
149
let mut accum: u64 = 0 ;
@@ -167,7 +167,7 @@ const RESEEDING_THRESHOLD: u64 = 1024*1024*1024; // something high enough to get
167
167
168
168
#[ bench]
169
169
fn reseeding_hc128_bytes ( b : & mut Bencher ) {
170
- let mut rng = ReseedingRng :: new ( Hc128Core :: new ( ) ,
170
+ let mut rng = ReseedingRng :: new ( Hc128Core :: from_entropy ( ) ,
171
171
RESEEDING_THRESHOLD ,
172
172
EntropyRng :: new ( ) ) ;
173
173
let mut buf = [ 0u8 ; BYTES_LEN ] ;
@@ -184,7 +184,7 @@ macro_rules! reseeding_uint {
184
184
( $fnn: ident, $ty: ty) => {
185
185
#[ bench]
186
186
fn $fnn( b: & mut Bencher ) {
187
- let mut rng = ReseedingRng :: new( Hc128Core :: new ( ) ,
187
+ let mut rng = ReseedingRng :: new( Hc128Core :: from_entropy ( ) ,
188
188
RESEEDING_THRESHOLD ,
189
189
EntropyRng :: new( ) ) ;
190
190
b. iter( || {
0 commit comments