@@ -120,6 +120,13 @@ impl SeedableRng for IsaacRng {
120
120
fn from_seed ( seed : Self :: Seed ) -> Self {
121
121
IsaacRng ( BlockRng :: < IsaacCore > :: from_seed ( seed) )
122
122
}
123
+
124
+ /// Create an ISAAC random number generator using an `u64` as seed.
125
+ /// If `seed == 0` this will produce the same stream of random numbers as
126
+ /// the reference implementation when used unseeded.
127
+ fn seed_from_u64 ( seed : u64 ) -> Self {
128
+ IsaacRng ( BlockRng :: < IsaacCore > :: seed_from_u64 ( seed) )
129
+ }
123
130
124
131
fn from_rng < S : RngCore > ( rng : S ) -> Result < Self , Error > {
125
132
BlockRng :: < IsaacCore > :: from_rng ( rng) . map ( |rng| IsaacRng ( rng) )
@@ -130,8 +137,9 @@ impl IsaacRng {
130
137
/// Create an ISAAC random number generator using an `u64` as seed.
131
138
/// If `seed == 0` this will produce the same stream of random numbers as
132
139
/// the reference implementation when used unseeded.
140
+ #[ deprecated( since="0.6.0" , note="use SeedableRng::seed_from_u64 instead" ) ]
133
141
pub fn new_from_u64 ( seed : u64 ) -> Self {
134
- IsaacRng ( BlockRng :: new ( IsaacCore :: new_from_u64 ( seed) ) )
142
+ Self :: seed_from_u64 ( seed)
135
143
}
136
144
}
137
145
@@ -302,22 +310,6 @@ impl IsaacCore {
302
310
303
311
Self { mem, a : w ( 0 ) , b : w ( 0 ) , c : w ( 0 ) }
304
312
}
305
-
306
- /// Create an ISAAC random number generator using an `u64` as seed.
307
- /// If `seed == 0` this will produce the same stream of random numbers as
308
- /// the reference implementation when used unseeded.
309
- fn new_from_u64 ( seed : u64 ) -> Self {
310
- let mut key = [ w ( 0 ) ; RAND_SIZE ] ;
311
- key[ 0 ] = w ( seed as u32 ) ;
312
- key[ 1 ] = w ( ( seed >> 32 ) as u32 ) ;
313
- // Initialize with only one pass.
314
- // A second pass does not improve the quality here, because all of the
315
- // seed was already available in the first round.
316
- // Not doing the second pass has the small advantage that if
317
- // `seed == 0` this method produces exactly the same state as the
318
- // reference implementation when used unseeded.
319
- Self :: init ( key, 1 )
320
- }
321
313
}
322
314
323
315
impl SeedableRng for IsaacCore {
@@ -333,6 +325,22 @@ impl SeedableRng for IsaacCore {
333
325
}
334
326
Self :: init ( seed_extended, 2 )
335
327
}
328
+
329
+ /// Create an ISAAC random number generator using an `u64` as seed.
330
+ /// If `seed == 0` this will produce the same stream of random numbers as
331
+ /// the reference implementation when used unseeded.
332
+ fn seed_from_u64 ( seed : u64 ) -> Self {
333
+ let mut key = [ w ( 0 ) ; RAND_SIZE ] ;
334
+ key[ 0 ] = w ( seed as u32 ) ;
335
+ key[ 1 ] = w ( ( seed >> 32 ) as u32 ) ;
336
+ // Initialize with only one pass.
337
+ // A second pass does not improve the quality here, because all of the
338
+ // seed was already available in the first round.
339
+ // Not doing the second pass has the small advantage that if
340
+ // `seed == 0` this method produces exactly the same state as the
341
+ // reference implementation when used unseeded.
342
+ Self :: init ( key, 1 )
343
+ }
336
344
337
345
fn from_rng < R : RngCore > ( mut rng : R ) -> Result < Self , Error > {
338
346
// Custom `from_rng` implementation that fills a seed with the same size
@@ -426,11 +434,11 @@ mod test {
426
434
#[ test]
427
435
fn test_isaac_new_uninitialized ( ) {
428
436
// Compare the results from initializing `IsaacRng` with
429
- // `new_from_u64 (0)`, to make sure it is the same as the reference
437
+ // `seed_from_u64 (0)`, to make sure it is the same as the reference
430
438
// implementation when used uninitialized.
431
439
// Note: We only test the first 16 integers, not the full 256 of the
432
440
// first block.
433
- let mut rng = IsaacRng :: new_from_u64 ( 0 ) ;
441
+ let mut rng = IsaacRng :: seed_from_u64 ( 0 ) ;
434
442
let mut results = [ 0u32 ; 16 ] ;
435
443
for i in results. iter_mut ( ) { * i = rng. next_u32 ( ) ; }
436
444
let expected: [ u32 ; 16 ] = [
0 commit comments