Skip to content

Commit 0396bc5

Browse files
committed
Remove random()
See rust-random#293.
1 parent d59be88 commit 0396bc5

File tree

2 files changed

+8
-77
lines changed

2 files changed

+8
-77
lines changed

src/lib.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
//! Utilities for random number generation
1212
//!
13-
//! The key functions are `random()` and `Rng::gen()`. These are polymorphic and
14-
//! so can be used to generate any type supporting the [`Uniform`] distribution
15-
//! (i.e. `T` where `Uniform`: `Distribution<T>`). Type inference
16-
//! means that often a simple call to `rand::random()` or `rng.gen()` will
17-
//! suffice, but sometimes an annotation is required, e.g.
18-
//! `rand::random::<f64>()`.
13+
//! The key function is `Rng::gen()`. It is polymorphic and so can be used to
14+
//! generate any type supporting the [`Uniform`] distribution (i.e. `T` where
15+
//! `Uniform`: `Distribution<T>`). Type inference means that often a simple call
16+
//! to `rng.gen()` will suffice, but sometimes an annotation is required, e.g.
17+
//! `rng.gen::<f64>()`.
1918
//!
2019
//! See the `distributions` submodule for sampling random numbers from
2120
//! distributions like normal and exponential.
@@ -88,11 +87,6 @@
8887
//! }
8988
//! ```
9089
//!
91-
//! ```rust
92-
//! let tuple = rand::random::<(f64, char)>();
93-
//! println!("{:?}", tuple)
94-
//! ```
95-
//!
9690
//! ## Monte Carlo estimation of π
9791
//!
9892
//! For this example, imagine we have a square with sides of length 2 and a unit
@@ -289,7 +283,7 @@ pub use error::{ErrorKind, Error};
289283

290284
// convenience and derived rngs
291285
#[cfg(feature="std")] pub use entropy_rng::EntropyRng;
292-
#[cfg(feature="std")] pub use thread_rng::{ThreadRng, thread_rng, random};
286+
#[cfg(feature="std")] pub use thread_rng::{ThreadRng, thread_rng};
293287

294288
use distributions::{Distribution, Uniform, Range};
295289
use distributions::range::SampleRange;

src/thread_rng.rs

+2-65
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
use std::cell::RefCell;
1414
use std::rc::Rc;
1515

16-
use {RngCore, CryptoRng, StdRng, SeedableRng, EntropyRng};
17-
use {Distribution, Uniform, Rng, Error};
16+
use {RngCore, CryptoRng, StdRng, SeedableRng, EntropyRng, Error};
1817
use reseeding::ReseedingRng;
1918

2019
// Number of generated bytes after which to reseed `TreadRng`.
@@ -99,57 +98,9 @@ impl RngCore for ThreadRng {
9998

10099
impl CryptoRng for ThreadRng {}
101100

102-
/// Generates a random value using the thread-local random number generator.
103-
///
104-
/// This is simply a shortcut for `thread_rng().gen()`. See [`thread_rng`] for
105-
/// documentation of the entropy source and [`Rand`] for documentation of
106-
/// distributions and type-specific generation.
107-
///
108-
/// # Examples
109-
///
110-
/// ```
111-
/// let x = rand::random::<u8>();
112-
/// println!("{}", x);
113-
///
114-
/// let y = rand::random::<f64>();
115-
/// println!("{}", y);
116-
///
117-
/// if rand::random() { // generates a boolean
118-
/// println!("Better lucky than good!");
119-
/// }
120-
/// ```
121-
///
122-
/// If you're calling `random()` in a loop, caching the generator as in the
123-
/// following example can increase performance.
124-
///
125-
/// ```
126-
/// use rand::Rng;
127-
///
128-
/// let mut v = vec![1, 2, 3];
129-
///
130-
/// for x in v.iter_mut() {
131-
/// *x = rand::random()
132-
/// }
133-
///
134-
/// // can be made faster by caching thread_rng
135-
///
136-
/// let mut rng = rand::thread_rng();
137-
///
138-
/// for x in v.iter_mut() {
139-
/// *x = rng.gen();
140-
/// }
141-
/// ```
142-
///
143-
/// [`thread_rng`]: fn.thread_rng.html
144-
/// [`Rand`]: trait.Rand.html
145-
#[inline]
146-
pub fn random<T>() -> T where Uniform: Distribution<T> {
147-
thread_rng().gen()
148-
}
149-
150101
#[cfg(test)]
151102
mod test {
152-
use super::*;
103+
use Rng;
153104

154105
#[test]
155106
#[cfg(feature="std")]
@@ -163,18 +114,4 @@ mod test {
163114
assert_eq!(v, b);
164115
assert_eq!(r.gen_range(0, 1), 0);
165116
}
166-
167-
#[test]
168-
fn test_random() {
169-
// not sure how to test this aside from just getting some values
170-
let _n : usize = random();
171-
let _f : f32 = random();
172-
let _o : Option<Option<i8>> = random();
173-
let _many : ((),
174-
(usize,
175-
isize,
176-
Option<(u32, (bool,))>),
177-
(u8, i8, u16, i16, u32, i32, u64, i64),
178-
(f32, (f64, (f64,)))) = random();
179-
}
180117
}

0 commit comments

Comments
 (0)