@@ -338,7 +338,14 @@ pub trait Rng {
338
338
fn next_u32 ( & mut self ) -> u32 ;
339
339
340
340
/// 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
+ }
342
349
343
350
/// Return the next random f32 selected from the half-open
344
351
/// interval `[0, 1)`.
@@ -393,6 +400,11 @@ pub trait Rng {
393
400
}
394
401
395
402
/// 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.
396
408
///
397
409
/// This method does *not* have a requirement to bear any fixed
398
410
/// relationship to the other methods, for example, it does *not*
@@ -414,7 +426,9 @@ pub trait Rng {
414
426
/// thread_rng().fill_bytes(&mut v);
415
427
/// println!("{:?}", &v[..]);
416
428
/// ```
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
+ }
418
432
419
433
/// Return a random value of a `Rand` type.
420
434
///
@@ -726,7 +740,7 @@ pub struct Closed01<F>(pub F);
726
740
727
741
/// The standard RNG. This is designed to be efficient on the current
728
742
/// platform.
729
- #[ derive( Clone , Debug ) ]
743
+ #[ derive( Copy , Clone , Debug ) ]
730
744
pub struct StdRng {
731
745
rng : IsaacWordRng ,
732
746
}
0 commit comments