Skip to content

Commit a720e5f

Browse files
committed
Reverse breaking changes
Likely most of these will happen with the next minor version bump
1 parent 8dc7b56 commit a720e5f

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

src/lib.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -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)]
730744
pub struct StdRng {
731745
rng: IsaacWordRng,
732746
}

src/prng/chacha.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const CHACHA_ROUNDS: u32 = 20; // Cryptographically secure from 8 upwards as of
2727
///
2828
/// [1]: D. J. Bernstein, [*ChaCha, a variant of
2929
/// Salsa20*](http://cr.yp.to/chacha.html)
30-
#[derive(Clone)]
30+
#[derive(Copy, Clone)]
3131
pub struct ChaChaRng {
3232
buffer: [u32; STATE_WORDS], // Internal buffer of output
3333
state: [u32; STATE_WORDS], // Initial state

src/prng/isaac.rs

+7
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const RAND_SIZE: usize = 1 << RAND_SIZE_LEN;
8787
///
8888
/// [3]: Jean-Philippe Aumasson, [*On the pseudo-random generator ISAAC*]
8989
/// (http://eprint.iacr.org/2006/438)
90+
#[derive(Copy)]
9091
pub struct IsaacRng {
9192
rsl: [u32; RAND_SIZE],
9293
mem: [w32; RAND_SIZE],
@@ -119,6 +120,12 @@ impl fmt::Debug for IsaacRng {
119120
}
120121

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

src/prng/isaac64.rs

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const RAND_SIZE: usize = 1 << RAND_SIZE_LEN;
7171
///
7272
/// [1]: Bob Jenkins, [*ISAAC and RC4*]
7373
/// (http://burtleburtle.net/bob/rand/isaac.html)
74+
#[derive(Copy)]
7475
pub struct Isaac64Rng {
7576
rsl: [u64; RAND_SIZE],
7677
mem: [w64; RAND_SIZE],
@@ -103,6 +104,12 @@ impl fmt::Debug for Isaac64Rng {
103104
}
104105

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

0 commit comments

Comments
 (0)