Rename TaskRng to ThreadRng

Since runtime is removed, rust has no tasks anymore and everything is moving
from being task-* to thread-*. Let’s rename TaskRng as well!

* Rename TaskRng to ThreadRng
* Rename task_rng to thread_rng

[breaking-change]
This commit is contained in:
Simonas Kazlauskas 2014-12-28 02:20:47 +02:00
parent 0201334439
commit 1e89bbcb67
21 changed files with 98 additions and 98 deletions

View File

@ -1347,7 +1347,7 @@ mod tests {
use core::cell::Cell; use core::cell::Cell;
use core::default::Default; use core::default::Default;
use core::mem; use core::mem;
use std::rand::{Rng, task_rng}; use std::rand::{Rng, thread_rng};
use std::rc::Rc; use std::rc::Rc;
use super::ElementSwaps; use super::ElementSwaps;
@ -1963,7 +1963,7 @@ mod tests {
fn test_sort() { fn test_sort() {
for len in range(4u, 25) { for len in range(4u, 25) {
for _ in range(0i, 100) { for _ in range(0i, 100) {
let mut v = task_rng().gen_iter::<uint>().take(len) let mut v = thread_rng().gen_iter::<uint>().take(len)
.collect::<Vec<uint>>(); .collect::<Vec<uint>>();
let mut v1 = v.clone(); let mut v1 = v.clone();
@ -1999,7 +1999,7 @@ mod tests {
// number this element is, i.e. the second elements // number this element is, i.e. the second elements
// will occur in sorted order. // will occur in sorted order.
let mut v = range(0, len).map(|_| { let mut v = range(0, len).map(|_| {
let n = task_rng().gen::<uint>() % 10; let n = thread_rng().gen::<uint>() % 10;
counts[n] += 1; counts[n] += 1;
(n, counts[n]) (n, counts[n])
}).collect::<Vec<(uint, int)>>(); }).collect::<Vec<(uint, int)>>();

View File

@ -112,7 +112,7 @@ mod tests {
#[test] #[test]
fn test_flate_round_trip() { fn test_flate_round_trip() {
let mut r = rand::task_rng(); let mut r = rand::thread_rng();
let mut words = vec!(); let mut words = vec!();
for _ in range(0u, 20) { for _ in range(0u, 20) {
let range = r.gen_range(1u, 10); let range = r.gen_range(1u, 10);

View File

@ -64,7 +64,7 @@ impl Rand for Exp1 {
/// use std::rand::distributions::{Exp, IndependentSample}; /// use std::rand::distributions::{Exp, IndependentSample};
/// ///
/// let exp = Exp::new(2.0); /// let exp = Exp::new(2.0);
/// let v = exp.ind_sample(&mut rand::task_rng()); /// let v = exp.ind_sample(&mut rand::thread_rng());
/// println!("{} is from a Exp(2) distribution", v); /// println!("{} is from a Exp(2) distribution", v);
/// ``` /// ```
#[deriving(Copy)] #[deriving(Copy)]

View File

@ -44,7 +44,7 @@ use super::{IndependentSample, Sample, Exp};
/// use std::rand::distributions::{IndependentSample, Gamma}; /// use std::rand::distributions::{IndependentSample, Gamma};
/// ///
/// let gamma = Gamma::new(2.0, 5.0); /// let gamma = Gamma::new(2.0, 5.0);
/// let v = gamma.ind_sample(&mut rand::task_rng()); /// let v = gamma.ind_sample(&mut rand::thread_rng());
/// println!("{} is from a Gamma(2, 5) distribution", v); /// println!("{} is from a Gamma(2, 5) distribution", v);
/// ``` /// ```
/// ///
@ -191,7 +191,7 @@ impl IndependentSample<f64> for GammaLargeShape {
/// use std::rand::distributions::{ChiSquared, IndependentSample}; /// use std::rand::distributions::{ChiSquared, IndependentSample};
/// ///
/// let chi = ChiSquared::new(11.0); /// let chi = ChiSquared::new(11.0);
/// let v = chi.ind_sample(&mut rand::task_rng()); /// let v = chi.ind_sample(&mut rand::thread_rng());
/// println!("{} is from a χ²(11) distribution", v) /// println!("{} is from a χ²(11) distribution", v)
/// ``` /// ```
pub struct ChiSquared { pub struct ChiSquared {
@ -248,7 +248,7 @@ impl IndependentSample<f64> for ChiSquared {
/// use std::rand::distributions::{FisherF, IndependentSample}; /// use std::rand::distributions::{FisherF, IndependentSample};
/// ///
/// let f = FisherF::new(2.0, 32.0); /// let f = FisherF::new(2.0, 32.0);
/// let v = f.ind_sample(&mut rand::task_rng()); /// let v = f.ind_sample(&mut rand::thread_rng());
/// println!("{} is from an F(2, 32) distribution", v) /// println!("{} is from an F(2, 32) distribution", v)
/// ``` /// ```
pub struct FisherF { pub struct FisherF {
@ -292,7 +292,7 @@ impl IndependentSample<f64> for FisherF {
/// use std::rand::distributions::{StudentT, IndependentSample}; /// use std::rand::distributions::{StudentT, IndependentSample};
/// ///
/// let t = StudentT::new(11.0); /// let t = StudentT::new(11.0);
/// let v = t.ind_sample(&mut rand::task_rng()); /// let v = t.ind_sample(&mut rand::thread_rng());
/// println!("{} is from a t(11) distribution", v) /// println!("{} is from a t(11) distribution", v)
/// ``` /// ```
pub struct StudentT { pub struct StudentT {

View File

@ -96,7 +96,7 @@ pub struct Weighted<T> {
/// Weighted { weight: 4, item: 'b' }, /// Weighted { weight: 4, item: 'b' },
/// Weighted { weight: 1, item: 'c' }); /// Weighted { weight: 1, item: 'c' });
/// let wc = WeightedChoice::new(items.as_mut_slice()); /// let wc = WeightedChoice::new(items.as_mut_slice());
/// let mut rng = rand::task_rng(); /// let mut rng = rand::thread_rng();
/// for _ in range(0u, 16) { /// for _ in range(0u, 16) {
/// // on average prints 'a' 4 times, 'b' 8 and 'c' twice. /// // on average prints 'a' 4 times, 'b' 8 and 'c' twice.
/// println!("{}", wc.ind_sample(&mut rng)); /// println!("{}", wc.ind_sample(&mut rng));

View File

@ -81,7 +81,7 @@ impl Rand for StandardNormal {
/// ///
/// // mean 2, standard deviation 3 /// // mean 2, standard deviation 3
/// let normal = Normal::new(2.0, 3.0); /// let normal = Normal::new(2.0, 3.0);
/// let v = normal.ind_sample(&mut rand::task_rng()); /// let v = normal.ind_sample(&mut rand::thread_rng());
/// println!("{} is from a N(2, 9) distribution", v) /// println!("{} is from a N(2, 9) distribution", v)
/// ``` /// ```
#[deriving(Copy)] #[deriving(Copy)]
@ -129,7 +129,7 @@ impl IndependentSample<f64> for Normal {
/// ///
/// // mean 2, standard deviation 3 /// // mean 2, standard deviation 3
/// let log_normal = LogNormal::new(2.0, 3.0); /// let log_normal = LogNormal::new(2.0, 3.0);
/// let v = log_normal.ind_sample(&mut rand::task_rng()); /// let v = log_normal.ind_sample(&mut rand::thread_rng());
/// println!("{} is from an ln N(2, 9) distribution", v) /// println!("{} is from an ln N(2, 9) distribution", v)
/// ``` /// ```
#[deriving(Copy)] #[deriving(Copy)]

View File

@ -39,7 +39,7 @@ use distributions::{Sample, IndependentSample};
/// ///
/// fn main() { /// fn main() {
/// let between = Range::new(10u, 10000u); /// let between = Range::new(10u, 10000u);
/// let mut rng = std::rand::task_rng(); /// let mut rng = std::rand::thread_rng();
/// let mut sum = 0; /// let mut sum = 0;
/// for _ in range(0u, 1000) { /// for _ in range(0u, 1000) {
/// sum += between.ind_sample(&mut rng); /// sum += between.ind_sample(&mut rng);

View File

@ -138,10 +138,10 @@ pub trait Rng {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::rand::{task_rng, Rng}; /// use std::rand::{thread_rng, Rng};
/// ///
/// let mut v = [0u8, .. 13579]; /// let mut v = [0u8, .. 13579];
/// task_rng().fill_bytes(&mut v); /// thread_rng().fill_bytes(&mut v);
/// println!("{}", v.as_slice()); /// println!("{}", v.as_slice());
/// ``` /// ```
fn fill_bytes(&mut self, dest: &mut [u8]) { fn fill_bytes(&mut self, dest: &mut [u8]) {
@ -173,9 +173,9 @@ pub trait Rng {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::rand::{task_rng, Rng}; /// use std::rand::{thread_rng, Rng};
/// ///
/// let mut rng = task_rng(); /// let mut rng = thread_rng();
/// let x: uint = rng.gen(); /// let x: uint = rng.gen();
/// println!("{}", x); /// println!("{}", x);
/// println!("{}", rng.gen::<(f64, bool)>()); /// println!("{}", rng.gen::<(f64, bool)>());
@ -191,9 +191,9 @@ pub trait Rng {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// use std::rand::{task_rng, Rng}; /// use std::rand::{thread_rng, Rng};
/// ///
/// let mut rng = task_rng(); /// let mut rng = thread_rng();
/// let x = rng.gen_iter::<uint>().take(10).collect::<Vec<uint>>(); /// let x = rng.gen_iter::<uint>().take(10).collect::<Vec<uint>>();
/// println!("{}", x); /// println!("{}", x);
/// println!("{}", rng.gen_iter::<(f64, bool)>().take(5) /// println!("{}", rng.gen_iter::<(f64, bool)>().take(5)
@ -218,9 +218,9 @@ pub trait Rng {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::rand::{task_rng, Rng}; /// use std::rand::{thread_rng, Rng};
/// ///
/// let mut rng = task_rng(); /// let mut rng = thread_rng();
/// let n: uint = rng.gen_range(0u, 10); /// let n: uint = rng.gen_range(0u, 10);
/// println!("{}", n); /// println!("{}", n);
/// let m: f64 = rng.gen_range(-40.0f64, 1.3e5f64); /// let m: f64 = rng.gen_range(-40.0f64, 1.3e5f64);
@ -236,9 +236,9 @@ pub trait Rng {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::rand::{task_rng, Rng}; /// use std::rand::{thread_rng, Rng};
/// ///
/// let mut rng = task_rng(); /// let mut rng = thread_rng();
/// println!("{}", rng.gen_weighted_bool(3)); /// println!("{}", rng.gen_weighted_bool(3));
/// ``` /// ```
fn gen_weighted_bool(&mut self, n: uint) -> bool { fn gen_weighted_bool(&mut self, n: uint) -> bool {
@ -250,9 +250,9 @@ pub trait Rng {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::rand::{task_rng, Rng}; /// use std::rand::{thread_rng, Rng};
/// ///
/// let s: String = task_rng().gen_ascii_chars().take(10).collect(); /// let s: String = thread_rng().gen_ascii_chars().take(10).collect();
/// println!("{}", s); /// println!("{}", s);
/// ``` /// ```
fn gen_ascii_chars<'a>(&'a mut self) -> AsciiGenerator<'a, Self> { fn gen_ascii_chars<'a>(&'a mut self) -> AsciiGenerator<'a, Self> {
@ -266,10 +266,10 @@ pub trait Rng {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// use std::rand::{task_rng, Rng}; /// use std::rand::{thread_rng, Rng};
/// ///
/// let choices = [1i, 2, 4, 8, 16, 32]; /// let choices = [1i, 2, 4, 8, 16, 32];
/// let mut rng = task_rng(); /// let mut rng = thread_rng();
/// println!("{}", rng.choose(&choices)); /// println!("{}", rng.choose(&choices));
/// assert_eq!(rng.choose(choices[..0]), None); /// assert_eq!(rng.choose(choices[..0]), None);
/// ``` /// ```
@ -286,9 +286,9 @@ pub trait Rng {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::rand::{task_rng, Rng}; /// use std::rand::{thread_rng, Rng};
/// ///
/// let mut rng = task_rng(); /// let mut rng = thread_rng();
/// let mut y = [1i, 2, 3]; /// let mut y = [1i, 2, 3];
/// rng.shuffle(&mut y); /// rng.shuffle(&mut y);
/// println!("{}", y.as_slice()); /// println!("{}", y.as_slice());
@ -520,8 +520,8 @@ mod test {
} }
} }
pub fn rng() -> MyRng<rand::TaskRng> { pub fn rng() -> MyRng<rand::ThreadRng> {
MyRng { inner: rand::task_rng() } MyRng { inner: rand::thread_rng() }
} }
pub fn weak_rng() -> MyRng<rand::XorShiftRng> { pub fn weak_rng() -> MyRng<rand::XorShiftRng> {

View File

@ -215,7 +215,7 @@ impl<T:Rand> Rand for Option<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::prelude::*; use std::prelude::*;
use std::rand::{Rng, task_rng, Open01, Closed01}; use std::rand::{Rng, thread_rng, Open01, Closed01};
struct ConstantRng(u64); struct ConstantRng(u64);
impl Rng for ConstantRng { impl Rng for ConstantRng {
@ -240,7 +240,7 @@ mod tests {
fn rand_open() { fn rand_open() {
// this is unlikely to catch an incorrect implementation that // this is unlikely to catch an incorrect implementation that
// generates exactly 0 or 1, but it keeps it sane. // generates exactly 0 or 1, but it keeps it sane.
let mut rng = task_rng(); let mut rng = thread_rng();
for _ in range(0u, 1_000) { for _ in range(0u, 1_000) {
// strict inequalities // strict inequalities
let Open01(f) = rng.gen::<Open01<f64>>(); let Open01(f) = rng.gen::<Open01<f64>>();
@ -253,7 +253,7 @@ mod tests {
#[test] #[test]
fn rand_closed() { fn rand_closed() {
let mut rng = task_rng(); let mut rng = thread_rng();
for _ in range(0u, 1_000) { for _ in range(0u, 1_000) {
// strict inequalities // strict inequalities
let Closed01(f) = rng.gen::<Closed01<f64>>(); let Closed01(f) = rng.gen::<Closed01<f64>>();

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
#![allow(non_snake_case)] #![allow(non_snake_case)]
use std::rand::{Rng, task_rng}; use std::rand::{Rng, thread_rng};
use stdtest::Bencher; use stdtest::Bencher;
use regex::{Regex, NoExpand}; use regex::{Regex, NoExpand};
@ -154,7 +154,7 @@ fn medium() -> Regex { regex!("[XYZ]ABCDEFGHIJKLMNOPQRSTUVWXYZ$") }
fn hard() -> Regex { regex!("[ -~]*ABCDEFGHIJKLMNOPQRSTUVWXYZ$") } fn hard() -> Regex { regex!("[ -~]*ABCDEFGHIJKLMNOPQRSTUVWXYZ$") }
fn gen_text(n: uint) -> String { fn gen_text(n: uint) -> String {
let mut rng = task_rng(); let mut rng = thread_rng();
let mut bytes = rng.gen_ascii_chars().map(|n| n as u8).take(n) let mut bytes = rng.gen_ascii_chars().map(|n| n as u8).take(n)
.collect::<Vec<u8>>(); .collect::<Vec<u8>>();
for (i, b) in bytes.iter_mut().enumerate() { for (i, b) in bytes.iter_mut().enumerate() {

View File

@ -392,10 +392,10 @@ mod tests {
#[test] #[test]
fn test_base64_random() { fn test_base64_random() {
use std::rand::{task_rng, random, Rng}; use std::rand::{thread_rng, random, Rng};
for _ in range(0u, 1000) { for _ in range(0u, 1000) {
let times = task_rng().gen_range(1u, 100); let times = thread_rng().gen_range(1u, 100);
let v = Vec::from_fn(times, |_| random::<u8>()); let v = Vec::from_fn(times, |_| random::<u8>());
assert_eq!(v.to_base64(STANDARD) assert_eq!(v.to_base64(STANDARD)
.from_base64() .from_base64()

View File

@ -79,7 +79,7 @@ impl RandomSipHasher {
/// Construct a new `RandomSipHasher` that is initialized with random keys. /// Construct a new `RandomSipHasher` that is initialized with random keys.
#[inline] #[inline]
pub fn new() -> RandomSipHasher { pub fn new() -> RandomSipHasher {
let mut r = rand::task_rng(); let mut r = rand::thread_rng();
let r0 = r.gen(); let r0 = r.gen();
let r1 = r.gen(); let r1 = r.gen();
RandomSipHasher { RandomSipHasher {

View File

@ -1438,7 +1438,7 @@ mod tests {
} }
fn make_rand_name() -> String { fn make_rand_name() -> String {
let mut rng = rand::task_rng(); let mut rng = rand::thread_rng();
let n = format!("TEST{}", rng.gen_ascii_chars().take(10u) let n = format!("TEST{}", rng.gen_ascii_chars().take(10u)
.collect::<String>()); .collect::<String>());
assert!(getenv(n.as_slice()).is_none()); assert!(getenv(n.as_slice()).is_none());

View File

@ -18,10 +18,10 @@
//! See the `distributions` submodule for sampling random numbers from //! See the `distributions` submodule for sampling random numbers from
//! distributions like normal and exponential. //! distributions like normal and exponential.
//! //!
//! # Task-local RNG //! # Thread-local RNG
//! //!
//! There is built-in support for a RNG associated with each task stored //! There is built-in support for a RNG associated with each thread stored
//! in task-local storage. This RNG can be accessed via `task_rng`, or //! in thread-local storage. This RNG can be accessed via `thread_rng`, or
//! used implicitly via `random`. This RNG is normally randomly seeded //! used implicitly via `random`. This RNG is normally randomly seeded
//! from an operating-system source of randomness, e.g. `/dev/urandom` on //! from an operating-system source of randomness, e.g. `/dev/urandom` on
//! Unix systems, and will automatically reseed itself from this source //! Unix systems, and will automatically reseed itself from this source
@ -61,7 +61,7 @@
//! use std::rand; //! use std::rand;
//! use std::rand::Rng; //! use std::rand::Rng;
//! //!
//! let mut rng = rand::task_rng(); //! let mut rng = rand::thread_rng();
//! if rng.gen() { // random bool //! if rng.gen() { // random bool
//! println!("int: {}, uint: {}", rng.gen::<int>(), rng.gen::<uint>()) //! println!("int: {}, uint: {}", rng.gen::<int>(), rng.gen::<uint>())
//! } //! }
@ -97,7 +97,7 @@
//! //!
//! fn main() { //! fn main() {
//! let between = Range::new(-1f64, 1.); //! let between = Range::new(-1f64, 1.);
//! let mut rng = rand::task_rng(); //! let mut rng = rand::thread_rng();
//! //!
//! let total = 1_000_000u; //! let total = 1_000_000u;
//! let mut in_circle = 0u; //! let mut in_circle = 0u;
@ -183,7 +183,7 @@
//! // The estimation will be more accurate with more simulations //! // The estimation will be more accurate with more simulations
//! let num_simulations = 10000u; //! let num_simulations = 10000u;
//! //!
//! let mut rng = rand::task_rng(); //! let mut rng = rand::thread_rng();
//! let random_door = Range::new(0u, 3); //! let random_door = Range::new(0u, 3);
//! //!
//! let (mut switch_wins, mut switch_losses) = (0u, 0u); //! let (mut switch_wins, mut switch_losses) = (0u, 0u);
@ -257,7 +257,7 @@ impl StdRng {
/// randomness from the operating system and use this in an /// randomness from the operating system and use this in an
/// expensive seeding operation. If one is only generating a small /// expensive seeding operation. If one is only generating a small
/// number of random numbers, or doesn't need the utmost speed for /// number of random numbers, or doesn't need the utmost speed for
/// generating each number, `task_rng` and/or `random` may be more /// generating each number, `thread_rng` and/or `random` may be more
/// appropriate. /// appropriate.
/// ///
/// Reading the randomness from the OS may fail, and any error is /// Reading the randomness from the OS may fail, and any error is
@ -307,28 +307,28 @@ pub fn weak_rng() -> XorShiftRng {
} }
} }
/// Controls how the task-local RNG is reseeded. /// Controls how the thread-local RNG is reseeded.
struct TaskRngReseeder; struct ThreadRngReseeder;
impl reseeding::Reseeder<StdRng> for TaskRngReseeder { impl reseeding::Reseeder<StdRng> for ThreadRngReseeder {
fn reseed(&mut self, rng: &mut StdRng) { fn reseed(&mut self, rng: &mut StdRng) {
*rng = match StdRng::new() { *rng = match StdRng::new() {
Ok(r) => r, Ok(r) => r,
Err(e) => panic!("could not reseed task_rng: {}", e) Err(e) => panic!("could not reseed thread_rng: {}", e)
} }
} }
} }
static TASK_RNG_RESEED_THRESHOLD: uint = 32_768; static THREAD_RNG_RESEED_THRESHOLD: uint = 32_768;
type TaskRngInner = reseeding::ReseedingRng<StdRng, TaskRngReseeder>; type ThreadRngInner = reseeding::ReseedingRng<StdRng, ThreadRngReseeder>;
/// The task-local RNG. /// The thread-local RNG.
pub struct TaskRng { pub struct ThreadRng {
rng: Rc<RefCell<TaskRngInner>>, rng: Rc<RefCell<ThreadRngInner>>,
} }
/// Retrieve the lazily-initialized task-local random number /// Retrieve the lazily-initialized thread-local random number
/// generator, seeded by the system. Intended to be used in method /// generator, seeded by the system. Intended to be used in method
/// chaining style, e.g. `task_rng().gen::<int>()`. /// chaining style, e.g. `thread_rng().gen::<int>()`.
/// ///
/// The RNG provided will reseed itself from the operating system /// The RNG provided will reseed itself from the operating system
/// after generating a certain amount of randomness. /// after generating a certain amount of randomness.
@ -337,23 +337,23 @@ pub struct TaskRng {
/// if the operating system random number generator is rigged to give /// if the operating system random number generator is rigged to give
/// the same sequence always. If absolute consistency is required, /// the same sequence always. If absolute consistency is required,
/// explicitly select an RNG, e.g. `IsaacRng` or `Isaac64Rng`. /// explicitly select an RNG, e.g. `IsaacRng` or `Isaac64Rng`.
pub fn task_rng() -> TaskRng { pub fn thread_rng() -> ThreadRng {
// used to make space in TLS for a random number generator // used to make space in TLS for a random number generator
thread_local!(static TASK_RNG_KEY: Rc<RefCell<TaskRngInner>> = { thread_local!(static THREAD_RNG_KEY: Rc<RefCell<ThreadRngInner>> = {
let r = match StdRng::new() { let r = match StdRng::new() {
Ok(r) => r, Ok(r) => r,
Err(e) => panic!("could not initialize task_rng: {}", e) Err(e) => panic!("could not initialize thread_rng: {}", e)
}; };
let rng = reseeding::ReseedingRng::new(r, let rng = reseeding::ReseedingRng::new(r,
TASK_RNG_RESEED_THRESHOLD, THREAD_RNG_RESEED_THRESHOLD,
TaskRngReseeder); ThreadRngReseeder);
Rc::new(RefCell::new(rng)) Rc::new(RefCell::new(rng))
}); });
TaskRng { rng: TASK_RNG_KEY.with(|t| t.clone()) } ThreadRng { rng: THREAD_RNG_KEY.with(|t| t.clone()) }
} }
impl Rng for TaskRng { impl Rng for ThreadRng {
fn next_u32(&mut self) -> u32 { fn next_u32(&mut self) -> u32 {
self.rng.borrow_mut().next_u32() self.rng.borrow_mut().next_u32()
} }
@ -368,7 +368,7 @@ impl Rng for TaskRng {
} }
} }
/// Generates a random value using the task-local random number generator. /// Generates a random value using the thread-local random number generator.
/// ///
/// `random()` can generate various types of random things, and so may require /// `random()` can generate various types of random things, and so may require
/// type hinting to generate the specific type you want. /// type hinting to generate the specific type you want.
@ -390,7 +390,7 @@ impl Rng for TaskRng {
/// ``` /// ```
#[inline] #[inline]
pub fn random<T: Rand>() -> T { pub fn random<T: Rand>() -> T {
task_rng().gen() thread_rng().gen()
} }
/// Randomly sample up to `amount` elements from an iterator. /// Randomly sample up to `amount` elements from an iterator.
@ -398,9 +398,9 @@ pub fn random<T: Rand>() -> T {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use std::rand::{task_rng, sample}; /// use std::rand::{thread_rng, sample};
/// ///
/// let mut rng = task_rng(); /// let mut rng = thread_rng();
/// let sample = sample(&mut rng, range(1i, 100), 5); /// let sample = sample(&mut rng, range(1i, 100), 5);
/// println!("{}", sample); /// println!("{}", sample);
/// ``` /// ```
@ -420,7 +420,7 @@ pub fn sample<T, I: Iterator<T>, R: Rng>(rng: &mut R,
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use prelude::*; use prelude::*;
use super::{Rng, task_rng, random, SeedableRng, StdRng, sample}; use super::{Rng, thread_rng, random, SeedableRng, StdRng, sample};
use iter::order; use iter::order;
struct ConstRng { i: u64 } struct ConstRng { i: u64 }
@ -453,7 +453,7 @@ mod test {
#[test] #[test]
fn test_gen_range() { fn test_gen_range() {
let mut r = task_rng(); let mut r = thread_rng();
for _ in range(0u, 1000) { for _ in range(0u, 1000) {
let a = r.gen_range(-3i, 42); let a = r.gen_range(-3i, 42);
assert!(a >= -3 && a < 42); assert!(a >= -3 && a < 42);
@ -473,20 +473,20 @@ mod test {
#[test] #[test]
#[should_fail] #[should_fail]
fn test_gen_range_panic_int() { fn test_gen_range_panic_int() {
let mut r = task_rng(); let mut r = thread_rng();
r.gen_range(5i, -2); r.gen_range(5i, -2);
} }
#[test] #[test]
#[should_fail] #[should_fail]
fn test_gen_range_panic_uint() { fn test_gen_range_panic_uint() {
let mut r = task_rng(); let mut r = thread_rng();
r.gen_range(5u, 2u); r.gen_range(5u, 2u);
} }
#[test] #[test]
fn test_gen_f64() { fn test_gen_f64() {
let mut r = task_rng(); let mut r = thread_rng();
let a = r.gen::<f64>(); let a = r.gen::<f64>();
let b = r.gen::<f64>(); let b = r.gen::<f64>();
debug!("{}", (a, b)); debug!("{}", (a, b));
@ -494,14 +494,14 @@ mod test {
#[test] #[test]
fn test_gen_weighted_bool() { fn test_gen_weighted_bool() {
let mut r = task_rng(); let mut r = thread_rng();
assert_eq!(r.gen_weighted_bool(0u), true); assert_eq!(r.gen_weighted_bool(0u), true);
assert_eq!(r.gen_weighted_bool(1u), true); assert_eq!(r.gen_weighted_bool(1u), true);
} }
#[test] #[test]
fn test_gen_ascii_str() { fn test_gen_ascii_str() {
let mut r = task_rng(); let mut r = thread_rng();
assert_eq!(r.gen_ascii_chars().take(0).count(), 0u); assert_eq!(r.gen_ascii_chars().take(0).count(), 0u);
assert_eq!(r.gen_ascii_chars().take(10).count(), 10u); assert_eq!(r.gen_ascii_chars().take(10).count(), 10u);
assert_eq!(r.gen_ascii_chars().take(16).count(), 16u); assert_eq!(r.gen_ascii_chars().take(16).count(), 16u);
@ -509,7 +509,7 @@ mod test {
#[test] #[test]
fn test_gen_vec() { fn test_gen_vec() {
let mut r = task_rng(); let mut r = thread_rng();
assert_eq!(r.gen_iter::<u8>().take(0).count(), 0u); assert_eq!(r.gen_iter::<u8>().take(0).count(), 0u);
assert_eq!(r.gen_iter::<u8>().take(10).count(), 10u); assert_eq!(r.gen_iter::<u8>().take(10).count(), 10u);
assert_eq!(r.gen_iter::<f64>().take(16).count(), 16u); assert_eq!(r.gen_iter::<f64>().take(16).count(), 16u);
@ -517,7 +517,7 @@ mod test {
#[test] #[test]
fn test_choose() { fn test_choose() {
let mut r = task_rng(); let mut r = thread_rng();
assert_eq!(r.choose(&[1i, 1, 1]).map(|&x|x), Some(1)); assert_eq!(r.choose(&[1i, 1, 1]).map(|&x|x), Some(1));
let v: &[int] = &[]; let v: &[int] = &[];
@ -526,7 +526,7 @@ mod test {
#[test] #[test]
fn test_shuffle() { fn test_shuffle() {
let mut r = task_rng(); let mut r = thread_rng();
let empty: &mut [int] = &mut []; let empty: &mut [int] = &mut [];
r.shuffle(empty); r.shuffle(empty);
let mut one = [1i]; let mut one = [1i];
@ -545,8 +545,8 @@ mod test {
} }
#[test] #[test]
fn test_task_rng() { fn test_thread_rng() {
let mut r = task_rng(); let mut r = thread_rng();
r.gen::<int>(); r.gen::<int>();
let mut v = [1i, 1, 1]; let mut v = [1i, 1, 1];
r.shuffle(&mut v); r.shuffle(&mut v);
@ -574,7 +574,7 @@ mod test {
let min_val = 1i; let min_val = 1i;
let max_val = 100i; let max_val = 100i;
let mut r = task_rng(); let mut r = thread_rng();
let vals = range(min_val, max_val).collect::<Vec<int>>(); let vals = range(min_val, max_val).collect::<Vec<int>>();
let small_sample = sample(&mut r, vals.iter(), 5); let small_sample = sample(&mut r, vals.iter(), 5);
let large_sample = sample(&mut r, vals.iter(), vals.len() + 5); let large_sample = sample(&mut r, vals.iter(), vals.len() + 5);
@ -589,7 +589,7 @@ mod test {
#[test] #[test]
fn test_std_rng_seeded() { fn test_std_rng_seeded() {
let s = task_rng().gen_iter::<uint>().take(256).collect::<Vec<uint>>(); let s = thread_rng().gen_iter::<uint>().take(256).collect::<Vec<uint>>();
let mut ra: StdRng = SeedableRng::from_seed(s.as_slice()); let mut ra: StdRng = SeedableRng::from_seed(s.as_slice());
let mut rb: StdRng = SeedableRng::from_seed(s.as_slice()); let mut rb: StdRng = SeedableRng::from_seed(s.as_slice());
assert!(order::equals(ra.gen_ascii_chars().take(100), assert!(order::equals(ra.gen_ascii_chars().take(100),
@ -598,7 +598,7 @@ mod test {
#[test] #[test]
fn test_std_rng_reseed() { fn test_std_rng_reseed() {
let s = task_rng().gen_iter::<uint>().take(256).collect::<Vec<uint>>(); let s = thread_rng().gen_iter::<uint>().take(256).collect::<Vec<uint>>();
let mut r: StdRng = SeedableRng::from_seed(s.as_slice()); let mut r: StdRng = SeedableRng::from_seed(s.as_slice());
let string1 = r.gen_ascii_chars().take(100).collect::<String>(); let string1 = r.gen_ascii_chars().take(100).collect::<String>();

View File

@ -394,7 +394,7 @@ mod tests {
for _ in range(0, N) { for _ in range(0, N) {
let tx = tx.clone(); let tx = tx.clone();
spawn(move|| { spawn(move|| {
let mut rng = rand::task_rng(); let mut rng = rand::thread_rng();
for _ in range(0, M) { for _ in range(0, M) {
if rng.gen_weighted_bool(N) { if rng.gen_weighted_bool(N) {
drop(R.write()); drop(R.write());

View File

@ -724,7 +724,7 @@ pub fn fresh_name(src: &ast::Ident) -> ast::Name {
// following: debug version. Could work in final except that it's incompatible with // following: debug version. Could work in final except that it's incompatible with
// good error messages and uses of struct names in ambiguous could-be-binding // good error messages and uses of struct names in ambiguous could-be-binding
// locations. Also definitely destroys the guarantee given above about ptr_eq. // locations. Also definitely destroys the guarantee given above about ptr_eq.
/*let num = rand::task_rng().gen_uint_range(0,0xffff); /*let num = rand::thread_rng().gen_uint_range(0,0xffff);
gensym(format!("{}_{}",ident_to_string(src),num))*/ gensym(format!("{}_{}",ident_to_string(src),num))*/
} }

View File

@ -83,7 +83,7 @@ fn read_line() {
} }
fn vec_plus() { fn vec_plus() {
let mut r = rand::task_rng(); let mut r = rand::thread_rng();
let mut v = Vec::new(); let mut v = Vec::new();
let mut i = 0; let mut i = 0;
@ -101,7 +101,7 @@ fn vec_plus() {
} }
fn vec_append() { fn vec_append() {
let mut r = rand::task_rng(); let mut r = rand::thread_rng();
let mut v = Vec::new(); let mut v = Vec::new();
let mut i = 0; let mut i = 0;
@ -122,7 +122,7 @@ fn vec_append() {
} }
fn vec_push_all() { fn vec_push_all() {
let mut r = rand::task_rng(); let mut r = rand::thread_rng();
let mut v = Vec::new(); let mut v = Vec::new();
for i in range(0u, 1500) { for i in range(0u, 1500) {

View File

@ -8,14 +8,14 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// ensure that the TaskRng isn't/doesn't become accidentally sendable. // ensure that the ThreadRng isn't/doesn't become accidentally sendable.
use std::rand; use std::rand;
fn test_send<S: Send>() {} fn test_send<S: Send>() {}
pub fn main() { pub fn main() {
test_send::<rand::TaskRng>(); test_send::<rand::ThreadRng>();
//~^ ERROR `core::kinds::Send` is not implemented //~^ ERROR `core::kinds::Send` is not implemented
//~^^ ERROR `core::kinds::Send` is not implemented //~^^ ERROR `core::kinds::Send` is not implemented
} }

View File

@ -10,7 +10,7 @@
use std::{char, os}; use std::{char, os};
use std::io::{File, Command}; use std::io::{File, Command};
use std::rand::{task_rng, Rng}; use std::rand::{thread_rng, Rng};
// creates unicode_input_multiple_files_{main,chars}.rs, where the // creates unicode_input_multiple_files_{main,chars}.rs, where the
// former imports the latter. `_chars` just contains an identifier // former imports the latter. `_chars` just contains an identifier
@ -19,7 +19,7 @@ use std::rand::{task_rng, Rng};
// this span used to upset the compiler). // this span used to upset the compiler).
fn random_char() -> char { fn random_char() -> char {
let mut rng = task_rng(); let mut rng = thread_rng();
// a subset of the XID_start Unicode table (ensuring that the // a subset of the XID_start Unicode table (ensuring that the
// compiler doesn't fail with an "unrecognised token" error) // compiler doesn't fail with an "unrecognised token" error)
let (lo, hi): (u32, u32) = match rng.gen_range(1u32, 4u32 + 1) { let (lo, hi): (u32, u32) = match rng.gen_range(1u32, 4u32 + 1) {

View File

@ -10,7 +10,7 @@
use std::{char, os}; use std::{char, os};
use std::io::{File, Command}; use std::io::{File, Command};
use std::rand::{task_rng, Rng}; use std::rand::{thread_rng, Rng};
// creates a file with `fn main() { <random ident> }` and checks the // creates a file with `fn main() { <random ident> }` and checks the
// compiler emits a span of the appropriate length (for the // compiler emits a span of the appropriate length (for the
@ -18,7 +18,7 @@ use std::rand::{task_rng, Rng};
// points, but should be the number of graphemes (FIXME #7043) // points, but should be the number of graphemes (FIXME #7043)
fn random_char() -> char { fn random_char() -> char {
let mut rng = task_rng(); let mut rng = thread_rng();
// a subset of the XID_start Unicode table (ensuring that the // a subset of the XID_start Unicode table (ensuring that the
// compiler doesn't fail with an "unrecognised token" error) // compiler doesn't fail with an "unrecognised token" error)
let (lo, hi): (u32, u32) = match rng.gen_range(1u32, 4u32 + 1) { let (lo, hi): (u32, u32) = match rng.gen_range(1u32, 4u32 + 1) {
@ -38,7 +38,7 @@ fn main() {
let main_file = tmpdir.join("span_main.rs"); let main_file = tmpdir.join("span_main.rs");
for _ in range(0u, 100) { for _ in range(0u, 100) {
let n = task_rng().gen_range(3u, 20); let n = thread_rng().gen_range(3u, 20);
{ {
let _ = write!(&mut File::create(&main_file).unwrap(), let _ = write!(&mut File::create(&main_file).unwrap(),

View File

@ -10,7 +10,7 @@
use std::task; use std::task;
use std::sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, Relaxed}; use std::sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, Relaxed};
use std::rand::{task_rng, Rng, Rand}; use std::rand::{thread_rng, Rng, Rand};
const REPEATS: uint = 5; const REPEATS: uint = 5;
const MAX_LEN: uint = 32; const MAX_LEN: uint = 32;
@ -59,7 +59,7 @@ pub fn main() {
// IDs start from 0. // IDs start from 0.
creation_count.store(0, Relaxed); creation_count.store(0, Relaxed);
let main = task_rng().gen_iter::<DropCounter>() let main = thread_rng().gen_iter::<DropCounter>()
.take(len) .take(len)
.collect::<Vec<DropCounter>>(); .collect::<Vec<DropCounter>>();