@@ -338,7 +338,14 @@ pub trait Rng {
338338 fn next_u32 ( & mut self ) -> u32 ;
339339
340340 /// Return the next random u64.
341- fn next_u64 ( & mut self ) -> u64 ;
341+ ///
342+ /// This function has a default implementation of `next_u32`. The
343+ /// default implementation should not be used in wrapper types since the
344+ /// wrapped RNG may have its own implementation which may be more efficient
345+ /// or even produce different results.
346+ fn next_u64 ( & mut self ) -> u64 {
347+ impls:: next_u64_via_u32 ( self )
348+ }
342349
343350 /// Return the next random f32 selected from the half-open
344351 /// interval `[0, 1)`.
@@ -393,6 +400,11 @@ pub trait Rng {
393400 }
394401
395402 /// Fill `dest` with random data.
403+ ///
404+ /// This function has a default implementation in terms of `next_u64`. The
405+ /// default implementation should not be used in wrapper types since the
406+ /// wrapped RNG may have its own implementation which may be more efficient
407+ /// or even produce different results.
396408 ///
397409 /// This method does *not* have a requirement to bear any fixed
398410 /// relationship to the other methods, for example, it does *not*
@@ -414,7 +426,9 @@ pub trait Rng {
414426 /// thread_rng().fill_bytes(&mut v);
415427 /// println!("{:?}", &v[..]);
416428 /// ```
417- fn fill_bytes ( & mut self , dest : & mut [ u8 ] ) ;
429+ fn fill_bytes ( & mut self , dest : & mut [ u8 ] ) {
430+ impls:: fill_bytes_via_u64 ( self , dest)
431+ }
418432
419433 /// Return a random value of a `Rand` type.
420434 ///
@@ -726,7 +740,7 @@ pub struct Closed01<F>(pub F);
726740
727741/// The standard RNG. This is designed to be efficient on the current
728742/// platform.
729- #[ derive( Clone , Debug ) ]
743+ #[ derive( Copy , Clone , Debug ) ]
730744pub struct StdRng {
731745 rng : IsaacWordRng ,
732746}
0 commit comments