@@ -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) )
@@ -139,8 +146,9 @@ impl IsaacRng {
139
146
/// Create an ISAAC random number generator using an `u64` as seed.
140
147
/// If `seed == 0` this will produce the same stream of random numbers as
141
148
/// the reference implementation when used unseeded.
149
+ #[ deprecated( since="0.6.0" , note="use SeedableRng::seed_from_u64 instead" ) ]
142
150
pub fn new_from_u64 ( seed : u64 ) -> Self {
143
- IsaacRng ( BlockRng :: new ( IsaacCore :: new_from_u64 ( seed) ) )
151
+ Self :: seed_from_u64 ( seed)
144
152
}
145
153
}
146
154
@@ -311,22 +319,6 @@ impl IsaacCore {
311
319
312
320
Self { mem, a : w ( 0 ) , b : w ( 0 ) , c : w ( 0 ) }
313
321
}
314
-
315
- /// Create an ISAAC random number generator using an `u64` as seed.
316
- /// If `seed == 0` this will produce the same stream of random numbers as
317
- /// the reference implementation when used unseeded.
318
- fn new_from_u64 ( seed : u64 ) -> Self {
319
- let mut key = [ w ( 0 ) ; RAND_SIZE ] ;
320
- key[ 0 ] = w ( seed as u32 ) ;
321
- key[ 1 ] = w ( ( seed >> 32 ) as u32 ) ;
322
- // Initialize with only one pass.
323
- // A second pass does not improve the quality here, because all of the
324
- // seed was already available in the first round.
325
- // Not doing the second pass has the small advantage that if
326
- // `seed == 0` this method produces exactly the same state as the
327
- // reference implementation when used unseeded.
328
- Self :: init ( key, 1 )
329
- }
330
322
}
331
323
332
324
impl SeedableRng for IsaacCore {
@@ -342,6 +334,22 @@ impl SeedableRng for IsaacCore {
342
334
}
343
335
Self :: init ( seed_extended, 2 )
344
336
}
337
+
338
+ /// Create an ISAAC random number generator using an `u64` as seed.
339
+ /// If `seed == 0` this will produce the same stream of random numbers as
340
+ /// the reference implementation when used unseeded.
341
+ fn seed_from_u64 ( seed : u64 ) -> Self {
342
+ let mut key = [ w ( 0 ) ; RAND_SIZE ] ;
343
+ key[ 0 ] = w ( seed as u32 ) ;
344
+ key[ 1 ] = w ( ( seed >> 32 ) as u32 ) ;
345
+ // Initialize with only one pass.
346
+ // A second pass does not improve the quality here, because all of the
347
+ // seed was already available in the first round.
348
+ // Not doing the second pass has the small advantage that if
349
+ // `seed == 0` this method produces exactly the same state as the
350
+ // reference implementation when used unseeded.
351
+ Self :: init ( key, 1 )
352
+ }
345
353
346
354
fn from_rng < R : RngCore > ( mut rng : R ) -> Result < Self , Error > {
347
355
// Custom `from_rng` implementation that fills a seed with the same size
@@ -435,11 +443,11 @@ mod test {
435
443
#[ test]
436
444
fn test_isaac_new_uninitialized ( ) {
437
445
// Compare the results from initializing `IsaacRng` with
438
- // `new_from_u64 (0)`, to make sure it is the same as the reference
446
+ // `seed_from_u64 (0)`, to make sure it is the same as the reference
439
447
// implementation when used uninitialized.
440
448
// Note: We only test the first 16 integers, not the full 256 of the
441
449
// first block.
442
- let mut rng = IsaacRng :: new_from_u64 ( 0 ) ;
450
+ let mut rng = IsaacRng :: seed_from_u64 ( 0 ) ;
443
451
let mut results = [ 0u32 ; 16 ] ;
444
452
for i in results. iter_mut ( ) { * i = rng. next_u32 ( ) ; }
445
453
let expected: [ u32 ; 16 ] = [
0 commit comments