Skip to content

Commit

Permalink
Revert some breaking changes
Browse files Browse the repository at this point in the history
Restore default implementations of next_u64 and fill_bytes
Restore new_unseeded functions (as wrappers)
  • Loading branch information
dhardy committed Dec 27, 2017
1 parent bf9f905 commit 8ad6e2a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,15 @@ pub trait Rng {
fn next_u32(&mut self) -> u32;

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

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

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

/// Return a random value of a `Rand` type.
///
Expand Down
6 changes: 6 additions & 0 deletions src/prng/isaac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ impl fmt::Debug for IsaacRng {
}

impl IsaacRng {
/// Create an ISAAC random number generator using the default
/// fixed seed.
pub fn new_unseeded() -> IsaacRng {
Self::new_from_u64(0)
}

/// Creates an ISAAC random number generator using an u64 as seed.
/// If `seed == 0` this will produce the same stream of random numbers as
/// the reference implementation when used unseeded.
Expand Down
6 changes: 6 additions & 0 deletions src/prng/isaac64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ impl fmt::Debug for Isaac64Rng {
}

impl Isaac64Rng {
/// Create a 64-bit ISAAC random number generator using the
/// default fixed seed.
pub fn new_unseeded() -> Isaac64Rng {
Self::new_from_u64(0)
}

/// Creates an ISAAC-64 random number generator using an u64 as seed.
/// If `seed == 0` this will produce the same stream of random numbers as
/// the reference implementation when used unseeded.
Expand Down

0 comments on commit 8ad6e2a

Please sign in to comment.