Skip to content

Commit b231ac2

Browse files
committed
Remove dependence on rand_jitter
This is a breaking change for anyone using rngs::JitterRng; such users should switch to rand_jitter::JitterRng.
1 parent 8cfe210 commit b231ac2

File tree

4 files changed

+12
-52
lines changed

4 files changed

+12
-52
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ appveyor = { repository = "rust-random/rand" }
2222
[features]
2323
default = ["std"] # without "std" rand uses libcore
2424
nightly = ["simd_support"] # enables all features requiring nightly rust
25-
std = ["rand_core/std", "alloc", "getrandom", "rand_jitter/std"]
25+
std = ["rand_core/std", "alloc", "getrandom"]
2626
alloc = ["rand_core/alloc"] # enables Vec and Box support (without std)
2727
i128_support = [] # enables i128 and u128 support
2828
simd_support = ["packed_simd"] # enables SIMD support
@@ -49,7 +49,6 @@ members = [
4949
[dependencies]
5050
rand_core = { path = "rand_core", version = "0.4" }
5151
rand_pcg = { path = "rand_pcg", version = "0.1" }
52-
rand_jitter = { path = "rand_jitter", version = "0.1" }
5352
rand_hc = { path = "rand_hc", version = "0.1" }
5453
getrandom = { version = "0.1", optional = true }
5554
log = { version = "0.4", optional = true }

benches/generators.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use test::{black_box, Bencher};
2525

2626
use rand::prelude::*;
2727
use rand::rngs::adapter::ReseedingRng;
28-
use rand::rngs::{OsRng, JitterRng};
28+
use rand::rngs::OsRng;
2929
use rand_isaac::{IsaacRng, Isaac64Rng};
3030
use rand_chacha::ChaChaRng;
3131
use rand_hc::{Hc128Rng, Hc128Core};
@@ -129,17 +129,6 @@ gen_uint!(gen_u64_std, u64, StdRng::from_entropy());
129129
gen_uint!(gen_u64_small, u64, SmallRng::from_entropy());
130130
gen_uint!(gen_u64_os, u64, OsRng::new().unwrap());
131131

132-
// Do not test JitterRng like the others by running it RAND_BENCH_N times per,
133-
// measurement, because it is way too slow. Only run it once.
134-
#[bench]
135-
fn gen_u64_jitter(b: &mut Bencher) {
136-
let mut rng = JitterRng::new().unwrap();
137-
b.iter(|| {
138-
rng.gen::<u64>()
139-
});
140-
b.bytes = size_of::<u64>() as u64;
141-
}
142-
143132
macro_rules! init_gen {
144133
($fnn:ident, $gen:ident) => {
145134
#[bench]
@@ -170,13 +159,6 @@ init_gen!(init_isaac, IsaacRng);
170159
init_gen!(init_isaac64, Isaac64Rng);
171160
init_gen!(init_chacha, ChaChaRng);
172161

173-
#[bench]
174-
fn init_jitter(b: &mut Bencher) {
175-
b.iter(|| {
176-
JitterRng::new().unwrap()
177-
});
178-
}
179-
180162

181163
const RESEEDING_THRESHOLD: u64 = 1024*1024*1024; // something high enough to get
182164
// deterministic measurements

src/lib.rs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858

5959
#[cfg(feature="simd_support")] extern crate packed_simd;
6060

61-
extern crate rand_jitter;
6261
#[cfg(feature = "getrandom")]
6362
extern crate getrandom;
6463

@@ -480,35 +479,16 @@ impl_as_byte_slice_arrays!(!div 4096, N,N,N,N,N,N,N,);
480479
/// [`OsRng`]: rngs::OsRng
481480
#[cfg(feature="std")]
482481
pub trait FromEntropy: SeedableRng {
483-
/// Creates a new instance, automatically seeded with fresh entropy.
482+
/// Creates a new instance of the RNG seeded from [`OsRng`].
484483
///
485-
/// Normally this will use `OsRng`, but if that fails `JitterRng` will be
486-
/// used instead. Both should be suitable for cryptography. It is possible
487-
/// that both entropy sources will fail though unlikely; failures would
488-
/// almost certainly be platform limitations or build issues, i.e. most
489-
/// applications targetting PC/mobile platforms should not need to worry
490-
/// about this failing.
484+
/// This method is equivalent to `SeedableRng::from_rng(OsRng).unwrap()`.
491485
///
492486
/// # Panics
493487
///
494-
/// If all entropy sources fail this will panic. If you need to handle
495-
/// errors, use the following code, equivalent aside from error handling:
496-
///
497-
/// ```
498-
/// # use rand::Error;
499-
/// use rand::prelude::*;
500-
/// use rand::rngs::OsRng;
501-
///
502-
/// # fn try_inner() -> Result<(), Error> {
503-
/// // This uses StdRng, but is valid for any R: SeedableRng
504-
/// let mut rng = StdRng::from_rng(OsRng)?;
505-
///
506-
/// println!("random number: {}", rng.gen_range(1, 10));
507-
/// # Ok(())
508-
/// # }
509-
///
510-
/// # try_inner().unwrap()
511-
/// ```
488+
/// If [`OsRng`] is unable to obtain secure entropy this method will panic.
489+
/// It is also possible for an RNG overriding the [`SeedableRng::from_rng`]
490+
/// method to cause a panic. Both causes are extremely unlikely to occur;
491+
/// most users need not worry about this.
512492
fn from_entropy() -> Self;
513493
}
514494

src/rngs/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
//!
2525
//! Generally the operating system will collect some entropy, remove bias, and
2626
//! use that to seed its own PRNG; [`OsRng`] provides an interface to this.
27-
//! [`JitterRng`] is an entropy collector included with Rand that measures
28-
//! jitter in the CPU execution time, and jitter in memory access time.
27+
//! Some alternatives are available although not normally required; see the
28+
//! [`rdrand`] and [`rand_jitter`] crates.
2929
//!
3030
//! ## Pseudo-random number generators
3131
//!
@@ -136,11 +136,12 @@
136136
//! [`SmallRng`]: rngs::SmallRng
137137
//! [`StdRng`]: rngs::StdRng
138138
//! [`ThreadRng`]: rngs::ThreadRng
139-
//! [`JitterRng`]: rngs::JitterRng
140139
//! [`mock::StepRng`]: rngs::mock::StepRng
141140
//! [`adapter::ReadRng`]: rngs::adapter::ReadRng
142141
//! [`adapter::ReseedingRng`]: rngs::adapter::ReseedingRng
143142
//! [`ChaChaRng`]: ../../rand_chacha/struct.ChaChaRng.html
143+
//! [`rdrand`]: https://crates.io/crates/rdrand
144+
//! [`rand_jitter`]: https://crates.io/crates/rand_jitter
144145
145146
pub mod adapter;
146147

@@ -151,8 +152,6 @@ mod small;
151152
mod std;
152153
#[cfg(feature="std")] pub(crate) mod thread;
153154

154-
155-
pub use rand_jitter::{JitterRng, TimerError};
156155
#[allow(deprecated)]
157156
#[cfg(feature="std")] pub use self::entropy::EntropyRng;
158157

0 commit comments

Comments
 (0)