@@ -989,7 +989,7 @@ impl Rng for ThreadRng {
989
989
///
990
990
/// `EntropyRng` uses the interface for random numbers provided by the operating
991
991
/// system ([`OsRng`]). If that returns an error, it will fall back to the
992
- /// [`JitterRng`] entropy collector. Occasionally it will then check if `OsRng`
992
+ /// [`JitterRng`] entropy collector. Every time it will then check if `OsRng`
993
993
/// is still not available, and switch back if possible.
994
994
///
995
995
/// [`OsRng`]: os/struct.OsRng.html
@@ -998,7 +998,6 @@ impl Rng for ThreadRng {
998
998
#[ derive( Debug ) ]
999
999
pub struct EntropyRng {
1000
1000
rng : EntropySource ,
1001
- counter : u32 ,
1002
1001
}
1003
1002
1004
1003
#[ cfg( feature="std" ) ]
@@ -1017,7 +1016,7 @@ impl EntropyRng {
1017
1016
/// those are done on first use. This is done to make `new` infallible,
1018
1017
/// and `try_fill_bytes` the only place to report errors.
1019
1018
pub fn new ( ) -> Self {
1020
- EntropyRng { rng : EntropySource :: None , counter : 0u32 }
1019
+ EntropyRng { rng : EntropySource :: None }
1021
1020
}
1022
1021
}
1023
1022
@@ -1078,22 +1077,15 @@ impl Rng for EntropyRng {
1078
1077
}
1079
1078
}
1080
1079
EntropySource :: Jitter ( ref mut rng) => {
1081
- if self . counter >= 8 {
1082
- if let Ok ( os_rng) = try_os_new ( dest) {
1083
- switch_rng = Some ( EntropySource :: Os ( os_rng) ) ;
1084
- } else {
1085
- self . counter = ( self . counter + 1 ) % 8 ;
1086
- return rng. try_fill_bytes ( dest) ; // use JitterRng
1087
- }
1080
+ if let Ok ( os_rng) = try_os_new ( dest) {
1081
+ switch_rng = Some ( EntropySource :: Os ( os_rng) ) ;
1088
1082
} else {
1089
- self . counter = ( self . counter + 1 ) % 8 ;
1090
1083
return rng. try_fill_bytes ( dest) ; // use JitterRng
1091
1084
}
1092
1085
}
1093
1086
}
1094
1087
if let Some ( rng) = switch_rng {
1095
1088
self . rng = rng;
1096
- self . counter = 0 ;
1097
1089
}
1098
1090
Ok ( ( ) )
1099
1091
}
0 commit comments