Skip to content

Commit 8ad6e2a

Browse files
committed
Revert some breaking changes
Restore default implementations of next_u64 and fill_bytes Restore new_unseeded functions (as wrappers)
1 parent bf9f905 commit 8ad6e2a

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/lib.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,15 @@ pub trait Rng {
343343
fn next_u32(&mut self) -> u32;
344344

345345
/// Return the next random u64.
346-
fn next_u64(&mut self) -> u64;
346+
///
347+
/// This function has a default implementation of `next_u32`. The
348+
/// default implementation should not be used in wrapper types since the
349+
/// wrapped RNG may have its own implementation which may be more efficient
350+
/// or even produce different results.
351+
fn next_u64(&mut self) -> u64 {
352+
// TODO: remove default implementation once impls module is exposed
353+
impls::next_u64_via_u32(self)
354+
}
347355

348356
/// Return the next random f32 selected from the half-open
349357
/// interval `[0, 1)`.
@@ -398,6 +406,11 @@ pub trait Rng {
398406
}
399407

400408
/// Fill `dest` with random data.
409+
///
410+
/// This function has a default implementation in terms of `next_u64`. The
411+
/// default implementation should not be used in wrapper types since the
412+
/// wrapped RNG may have its own implementation which may be more efficient
413+
/// or even produce different results.
401414
///
402415
/// This method does *not* have a requirement to bear any fixed
403416
/// relationship to the other methods, for example, it does *not*
@@ -419,7 +432,10 @@ pub trait Rng {
419432
/// thread_rng().fill_bytes(&mut v);
420433
/// println!("{:?}", &v[..]);
421434
/// ```
422-
fn fill_bytes(&mut self, dest: &mut [u8]);
435+
fn fill_bytes(&mut self, dest: &mut [u8]) {
436+
// TODO: remove default implementation once impls module is exposed
437+
impls::fill_bytes_via_u64(self, dest)
438+
}
423439

424440
/// Return a random value of a `Rand` type.
425441
///

src/prng/isaac.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ impl fmt::Debug for IsaacRng {
119119
}
120120

121121
impl IsaacRng {
122+
/// Create an ISAAC random number generator using the default
123+
/// fixed seed.
124+
pub fn new_unseeded() -> IsaacRng {
125+
Self::new_from_u64(0)
126+
}
127+
122128
/// Creates an ISAAC random number generator using an u64 as seed.
123129
/// If `seed == 0` this will produce the same stream of random numbers as
124130
/// the reference implementation when used unseeded.

src/prng/isaac64.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ impl fmt::Debug for Isaac64Rng {
105105
}
106106

107107
impl Isaac64Rng {
108+
/// Create a 64-bit ISAAC random number generator using the
109+
/// default fixed seed.
110+
pub fn new_unseeded() -> Isaac64Rng {
111+
Self::new_from_u64(0)
112+
}
113+
108114
/// Creates an ISAAC-64 random number generator using an u64 as seed.
109115
/// If `seed == 0` this will produce the same stream of random numbers as
110116
/// the reference implementation when used unseeded.

0 commit comments

Comments
 (0)