diff --git a/benches/misc.rs b/benches/misc.rs index a1822a53a83..b7e3e43f2cb 100644 --- a/benches/misc.rs +++ b/benches/misc.rs @@ -149,17 +149,6 @@ fn gen_1k_iter_repeat(b: &mut Bencher) { b.bytes = 1024; } -#[bench] -#[allow(deprecated)] -fn gen_1k_gen_iter(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap(); - b.iter(|| { - let v: Vec = rng.gen_iter().take(128).collect(); - v - }); - b.bytes = 1024; -} - #[bench] fn gen_1k_sample_iter(b: &mut Bencher) { use rand::distributions::{Distribution, Standard}; diff --git a/src/distributions/mod.rs b/src/distributions/mod.rs index 4a2a4f2e046..6f6523b15e4 100644 --- a/src/distributions/mod.rs +++ b/src/distributions/mod.rs @@ -170,8 +170,6 @@ use Rng; #[doc(inline)] pub use self::other::Alphanumeric; #[doc(inline)] pub use self::uniform::Uniform; #[doc(inline)] pub use self::float::{OpenClosed01, Open01}; -#[deprecated(since="0.5.0", note="use Uniform instead")] -pub use self::uniform::Uniform as Range; #[cfg(feature="std")] #[doc(inline)] pub use self::gamma::{Gamma, ChiSquared, FisherF, StudentT}; #[cfg(feature="std")] @@ -215,89 +213,6 @@ mod ziggurat_tables; #[cfg(feature="std")] use distributions::float::IntoFloat; -/// Types that can be used to create a random instance of `Support`. -#[deprecated(since="0.5.0", note="use Distribution instead")] -pub trait Sample { - /// Generate a random value of `Support`, using `rng` as the - /// source of randomness. - fn sample(&mut self, rng: &mut R) -> Support; -} - -/// `Sample`s that do not require keeping track of state. -/// -/// Since no state is recorded, each sample is (statistically) -/// independent of all others, assuming the `Rng` used has this -/// property. -#[allow(deprecated)] -#[deprecated(since="0.5.0", note="use Distribution instead")] -pub trait IndependentSample: Sample { - /// Generate a random value. - fn ind_sample(&self, &mut R) -> Support; -} - -/// DEPRECATED: Use `distributions::uniform` instead. -#[deprecated(since="0.5.0", note="use uniform instead")] -pub mod range { - pub use distributions::uniform::Uniform as Range; - pub use distributions::uniform::SampleUniform as SampleRange; -} - -#[allow(deprecated)] -mod impls { - use Rng; - use distributions::{Distribution, Sample, IndependentSample, - WeightedChoice}; - #[cfg(feature="std")] - use distributions::exponential::Exp; - #[cfg(feature="std")] - use distributions::gamma::{Gamma, ChiSquared, FisherF, StudentT}; - #[cfg(feature="std")] - use distributions::normal::{Normal, LogNormal}; - use distributions::range::{Range, SampleRange}; - - impl<'a, T: Clone> Sample for WeightedChoice<'a, T> { - fn sample(&mut self, rng: &mut R) -> T { - Distribution::sample(self, rng) - } - } - impl<'a, T: Clone> IndependentSample for WeightedChoice<'a, T> { - fn ind_sample(&self, rng: &mut R) -> T { - Distribution::sample(self, rng) - } - } - - impl Sample for Range { - fn sample(&mut self, rng: &mut R) -> T { - Distribution::sample(self, rng) - } - } - impl IndependentSample for Range { - fn ind_sample(&self, rng: &mut R) -> T { - Distribution::sample(self, rng) - } - } - - #[cfg(feature="std")] - macro_rules! impl_f64 { - ($($name: ident), *) => { - $( - impl Sample for $name { - fn sample(&mut self, rng: &mut R) -> f64 { - Distribution::sample(self, rng) - } - } - impl IndependentSample for $name { - fn ind_sample(&self, rng: &mut R) -> f64 { - Distribution::sample(self, rng) - } - } - )* - } - } - #[cfg(feature="std")] - impl_f64!(Exp, Gamma, ChiSquared, FisherF, StudentT, Normal, LogNormal); -} - /// Types (distributions) that can be used to create a random instance of `T`. /// /// It is possible to sample from a distribution through both the @@ -445,13 +360,6 @@ impl<'a, D, R, T> Iterator for DistIter<'a, D, R, T> #[derive(Clone, Copy, Debug)] pub struct Standard; -#[allow(deprecated)] -impl ::Rand for T where Standard: Distribution { - fn rand(rng: &mut R) -> Self { - Standard.sample(rng) - } -} - /// A value with a particular weight for use with `WeightedChoice`. #[derive(Copy, Clone, Debug)] @@ -637,7 +545,6 @@ fn ziggurat( #[cfg(test)] mod tests { - use Rng; use rngs::mock::StepRng; use super::{WeightedChoice, Weighted, Distribution}; @@ -743,31 +650,6 @@ mod tests { Weighted { weight: 1, item: 3 }]); } - #[test] #[allow(deprecated)] - fn test_backwards_compat_sample() { - use distributions::{Sample, IndependentSample}; - - struct Constant { val: T } - impl Sample for Constant { - fn sample(&mut self, _: &mut R) -> T { self.val } - } - impl IndependentSample for Constant { - fn ind_sample(&self, _: &mut R) -> T { self.val } - } - - let mut sampler = Constant{ val: 293 }; - assert_eq!(sampler.sample(&mut ::test::rng(233)), 293); - assert_eq!(sampler.ind_sample(&mut ::test::rng(234)), 293); - } - - #[cfg(feature="std")] - #[test] #[allow(deprecated)] - fn test_backwards_compat_exp() { - use distributions::{IndependentSample, Exp}; - let sampler = Exp::new(1.0); - sampler.ind_sample(&mut ::test::rng(235)); - } - #[cfg(feature="std")] #[test] fn test_distributions_iter() { diff --git a/src/lib.rs b/src/lib.rs index eb23f86b87f..ea427c2c8dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -299,25 +299,11 @@ pub mod isaac { //////////////////////////////////////////////////////////////////////////////// -use core::{marker, mem, slice}; +use core::{mem, slice}; use distributions::{Distribution, Standard}; use distributions::uniform::{SampleUniform, UniformSampler}; -/// A type that can be randomly generated using an [`Rng`]. -/// -/// This is merely an adapter around the [`Standard`] distribution for -/// convenience and backwards-compatibility. -/// -/// [`Rng`]: trait.Rng.html -/// [`Standard`]: distributions/struct.Standard.html -#[deprecated(since="0.5.0", note="replaced by distributions::Standard")] -pub trait Rand : Sized { - /// Generates a random instance of this type using the specified source of - /// randomness. - fn rand(rng: &mut R) -> Self; -} - /// An automatically-implemented extension trait on [`RngCore`] providing high-level /// generic methods for sampling values and other convenience methods. /// @@ -606,67 +592,6 @@ pub trait Rng: RngCore { values.swap(i, self.gen_range(0, i + 1)); } } - - /// Return an iterator that will yield an infinite number of randomly - /// generated items. - /// - /// # Example - /// - /// ``` - /// # #![allow(deprecated)] - /// use rand::{thread_rng, Rng}; - /// - /// let mut rng = thread_rng(); - /// let x = rng.gen_iter::().take(10).collect::>(); - /// println!("{:?}", x); - /// println!("{:?}", rng.gen_iter::<(f64, bool)>().take(5) - /// .collect::>()); - /// ``` - #[allow(deprecated)] - #[deprecated(since="0.5.0", note="use Rng::sample_iter(&Standard) instead")] - fn gen_iter(&mut self) -> Generator where Standard: Distribution { - Generator { rng: self, _marker: marker::PhantomData } - } - - /// Return a bool with a 1 in n chance of true - /// - /// # Example - /// - /// ``` - /// # #![allow(deprecated)] - /// use rand::{thread_rng, Rng}; - /// - /// let mut rng = thread_rng(); - /// assert_eq!(rng.gen_weighted_bool(0), true); - /// assert_eq!(rng.gen_weighted_bool(1), true); - /// // Just like `rng.gen::()` a 50-50% chance, but using a slower - /// // method with different results. - /// println!("{}", rng.gen_weighted_bool(2)); - /// // First meaningful use of `gen_weighted_bool`. - /// println!("{}", rng.gen_weighted_bool(3)); - /// ``` - #[deprecated(since="0.5.0", note="use gen_bool instead")] - fn gen_weighted_bool(&mut self, n: u32) -> bool { - // Short-circuit after `n <= 1` to avoid panic in `gen_range` - n <= 1 || self.gen_range(0, n) == 0 - } - - /// Return an iterator of random characters from the set A-Z,a-z,0-9. - /// - /// # Example - /// - /// ``` - /// # #![allow(deprecated)] - /// use rand::{thread_rng, Rng}; - /// - /// let s: String = thread_rng().gen_ascii_chars().take(10).collect(); - /// println!("{}", s); - /// ``` - #[allow(deprecated)] - #[deprecated(since="0.5.0", note="use sample_iter(&Alphanumeric) instead")] - fn gen_ascii_chars(&mut self) -> AsciiGenerator<&mut Self> { - AsciiGenerator { rng: self } - } } impl Rng for R {} @@ -767,55 +692,6 @@ macro_rules! impl_as_byte_slice_arrays { impl_as_byte_slice_arrays!(32, N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,); impl_as_byte_slice_arrays!(!div 4096, N,N,N,N,N,N,N,); -/// Iterator which will generate a stream of random items. -/// -/// This iterator is created via the [`gen_iter`] method on [`Rng`]. -/// -/// [`gen_iter`]: trait.Rng.html#method.gen_iter -/// [`Rng`]: trait.Rng.html -#[derive(Debug)] -#[allow(deprecated)] -#[deprecated(since="0.5.0", note="use Rng::sample_iter instead")] -pub struct Generator { - rng: R, - _marker: marker::PhantomData T>, -} - -#[allow(deprecated)] -impl Iterator for Generator where Standard: Distribution { - type Item = T; - - fn next(&mut self) -> Option { - Some(self.rng.gen()) - } -} - -/// Iterator which will continuously generate random ascii characters. -/// -/// This iterator is created via the [`gen_ascii_chars`] method on [`Rng`]. -/// -/// [`gen_ascii_chars`]: trait.Rng.html#method.gen_ascii_chars -/// [`Rng`]: trait.Rng.html -#[derive(Debug)] -#[allow(deprecated)] -#[deprecated(since="0.5.0", note="use distributions::Alphanumeric instead")] -pub struct AsciiGenerator { - rng: R, -} - -#[allow(deprecated)] -impl Iterator for AsciiGenerator { - type Item = char; - - fn next(&mut self) -> Option { - const GEN_ASCII_STR_CHARSET: &[u8] = - b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\ - abcdefghijklmnopqrstuvwxyz\ - 0123456789"; - Some(*self.rng.choose(GEN_ASCII_STR_CHARSET).unwrap() as char) - } -} - /// A convenience extension to [`SeedableRng`] allowing construction from fresh /// entropy. This trait is automatically implemented for any PRNG implementing @@ -888,25 +764,6 @@ impl FromEntropy for R { } -/// DEPRECATED: use [`SmallRng`] instead. -/// -/// Create a weak random number generator with a default algorithm and seed. -/// -/// It returns the fastest `Rng` algorithm currently available in Rust without -/// consideration for cryptography or security. If you require a specifically -/// seeded `Rng` for consistency over time you should pick one algorithm and -/// create the `Rng` yourself. -/// -/// This will seed the generator with randomness from `thread_rng`. -/// -/// [`SmallRng`]: rngs/struct.SmallRng.html -#[deprecated(since="0.5.0", note="removed in favor of SmallRng")] -#[cfg(feature="std")] -pub fn weak_rng() -> XorShiftRng { - XorShiftRng::from_rng(thread_rng()).unwrap_or_else(|err| - panic!("weak_rng failed: {:?}", err)) -} - /// Generates a random value using the thread-local random number generator. /// /// This is simply a shortcut for `thread_rng().gen()`. See [`thread_rng`] for @@ -931,7 +788,6 @@ pub fn weak_rng() -> XorShiftRng { /// following example can increase performance. /// /// ``` -/// # #![allow(deprecated)] /// use rand::Rng; /// /// let mut v = vec![1, 2, 3]; @@ -957,33 +813,6 @@ pub fn random() -> T where Standard: Distribution { thread_rng().gen() } -/// DEPRECATED: use `seq::sample_iter` instead. -/// -/// Randomly sample up to `amount` elements from a finite iterator. -/// The order of elements in the sample is not random. -/// -/// # Example -/// -/// ``` -/// # #![allow(deprecated)] -/// use rand::{thread_rng, sample}; -/// -/// let mut rng = thread_rng(); -/// let sample = sample(&mut rng, 1..100, 5); -/// println!("{:?}", sample); -/// ``` -#[cfg(feature="std")] -#[inline] -#[deprecated(since="0.4.0", note="renamed to seq::sample_iter")] -pub fn sample(rng: &mut R, iterable: I, amount: usize) -> Vec - where I: IntoIterator, - R: Rng, -{ - // the legacy sample didn't care whether amount was met - seq::sample_iter(rng, iterable, amount) - .unwrap_or_else(|e| e) -} - #[cfg(test)] mod test { use rngs::mock::StepRng; @@ -1105,14 +934,6 @@ mod test { r.gen_range(5, 2); } - #[test] - #[allow(deprecated)] - fn test_gen_weighted_bool() { - let mut r = rng(104); - assert_eq!(r.gen_weighted_bool(0), true); - assert_eq!(r.gen_weighted_bool(1), true); - } - #[test] fn test_gen_bool() { let mut r = rng(105); diff --git a/src/prng/chacha.rs b/src/prng/chacha.rs index c81af624737..1bd8d9953bf 100644 --- a/src/prng/chacha.rs +++ b/src/prng/chacha.rs @@ -107,31 +107,6 @@ impl SeedableRng for ChaChaRng { impl CryptoRng for ChaChaRng {} impl ChaChaRng { - /// Create an ChaCha random number generator using the default - /// fixed key of 8 zero words. - /// - /// # Examples - /// - /// ``` - /// # #![allow(deprecated)] - /// use rand::{RngCore, ChaChaRng}; - /// - /// let mut ra = ChaChaRng::new_unseeded(); - /// println!("{:?}", ra.next_u32()); - /// println!("{:?}", ra.next_u32()); - /// ``` - /// - /// Since this equivalent to a RNG with a fixed seed, repeated executions - /// of an unseeded RNG will produce the same result. This code sample will - /// consistently produce: - /// - /// - 2917185654 - /// - 2419978656 - #[deprecated(since="0.5.0", note="use the FromEntropy or SeedableRng trait")] - pub fn new_unseeded() -> ChaChaRng { - ChaChaRng::from_seed([0; SEED_WORDS*4]) - } - /// Get the offset from the start of the stream, in 32-bit words. /// /// Since the generated blocks are 16 words (24) long and the diff --git a/src/prng/isaac.rs b/src/prng/isaac.rs index db4a7361d41..b2b0cb072ce 100644 --- a/src/prng/isaac.rs +++ b/src/prng/isaac.rs @@ -127,15 +127,6 @@ impl SeedableRng for IsaacRng { } impl IsaacRng { - /// Create an ISAAC random number generator using the default - /// fixed seed. - /// - /// DEPRECATED. `IsaacRng::new_from_u64(0)` will produce identical results. - #[deprecated(since="0.5.0", note="use the FromEntropy or SeedableRng trait")] - pub fn new_unseeded() -> Self { - Self::new_from_u64(0) - } - /// Create 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. diff --git a/src/prng/isaac64.rs b/src/prng/isaac64.rs index e92286215d9..a2a62afa372 100644 --- a/src/prng/isaac64.rs +++ b/src/prng/isaac64.rs @@ -117,15 +117,6 @@ impl SeedableRng for Isaac64Rng { } impl Isaac64Rng { - /// Create a 64-bit ISAAC random number generator using the - /// default fixed seed. - /// - /// DEPRECATED. `Isaac64Rng::new_from_u64(0)` will produce identical results. - #[deprecated(since="0.5.0", note="use the FromEntropy or SeedableRng trait")] - pub fn new_unseeded() -> Self { - Self::new_from_u64(0) - } - /// Create 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. diff --git a/src/prng/xorshift.rs b/src/prng/xorshift.rs index 5f96170169b..6a9775d8d5f 100644 --- a/src/prng/xorshift.rs +++ b/src/prng/xorshift.rs @@ -40,24 +40,6 @@ impl fmt::Debug for XorShiftRng { } } -impl XorShiftRng { - /// Creates a new XorShiftRng instance which is not seeded. - /// - /// The initial values of this RNG are constants, so all generators created - /// by this function will yield the same stream of random numbers. It is - /// highly recommended that this is created through `SeedableRng` instead of - /// this function - #[deprecated(since="0.5.0", note="use the FromEntropy or SeedableRng trait")] - pub fn new_unseeded() -> XorShiftRng { - XorShiftRng { - x: w(0x193a6754), - y: w(0xa8a7d469), - z: w(0x97830e05), - w: w(0x113ba7bb), - } - } -} - impl RngCore for XorShiftRng { #[inline] fn next_u32(&mut self) -> u32 {