std: Move rand to librand.

This functionality is not super-core and so doesn't need to be included
in std. It's possible that std may need rand (it does a little bit now,
for io::test) in which case the functionality required could be moved to
a secret hidden module and reexposed by librand.

Unfortunately, using #[deprecated] here is hard: there's too much to
mock to make it feasible, since we have to ensure that programs still
typecheck to reach the linting phase.
This commit is contained in:
Huon Wilson 2014-03-02 11:23:04 +11:00
parent 74bfa7108a
commit 6fa4bbeed4
18 changed files with 161 additions and 198 deletions

View File

@ -50,14 +50,14 @@
################################################################################
TARGET_CRATES := std extra green rustuv native flate arena glob term semver \
uuid serialize sync getopts collections num test time
uuid serialize sync getopts collections num test time rand
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc
DEPS_std := native:rustrt native:compiler-rt
DEPS_extra := std term sync serialize getopts collections time
DEPS_green := std native:context_switch
DEPS_extra := std term sync serialize getopts collections time rand
DEPS_green := std rand native:context_switch
DEPS_rustuv := std native:uv native:uv_support
DEPS_native := std
DEPS_syntax := std term serialize collections
@ -71,15 +71,16 @@ DEPS_glob := std
DEPS_serialize := std collections
DEPS_term := std collections
DEPS_semver := std
DEPS_uuid := std serialize
DEPS_uuid := std serialize rand
DEPS_sync := std
DEPS_getopts := std
DEPS_collections := std
DEPS_collections := std rand
DEPS_fourcc := syntax std
DEPS_hexfloat := syntax std
DEPS_num := std
DEPS_num := std rand
DEPS_test := std extra collections getopts serialize term
DEPS_time := std serialize
DEPS_rand := std
TOOL_DEPS_compiletest := test green rustuv getopts
TOOL_DEPS_rustdoc := rustdoc native

View File

@ -11,7 +11,7 @@
# except according to those terms.
# This creates the tables used for distributions implemented using the
# ziggurat algorithm in `std::rand::distributions;`. They are
# ziggurat algorithm in `rand::distributions;`. They are
# (basically) the tables as used in the ZIGNOR variant (Doornik 2005).
# They are changed rarely, so the generated file should be checked in
# to git.

View File

@ -10,9 +10,9 @@
//! The exponential distribution.
use num::Float;
use rand::{Rng, Rand};
use rand::distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
use std::num::Float;
use {Rng, Rand};
use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
/// A wrapper around an `f64` to generate Exp(1) random numbers.
///
@ -58,8 +58,7 @@ impl Rand for Exp1 {
/// # Example
///
/// ```rust
/// use std::rand;
/// use std::rand::distributions::{Exp, IndependentSample};
/// use rand::distributions::{Exp, IndependentSample};
///
/// let exp = Exp::new(2.0);
/// let v = exp.ind_sample(&mut rand::task_rng());
@ -91,10 +90,9 @@ impl IndependentSample<f64> for Exp {
#[cfg(test)]
mod test {
use rand::distributions::*;
use prelude::*;
use rand::*;
use super::*;
use distributions::{Sample, IndependentSample};
use {Rng, task_rng};
use super::Exp;
#[test]
fn test_exp() {
@ -121,11 +119,10 @@ mod test {
mod bench {
extern crate test;
use self::test::BenchHarness;
use mem::size_of;
use prelude::*;
use rand::{XorShiftRng, RAND_BENCH_N};
use super::*;
use rand::distributions::*;
use std::mem::size_of;
use {XorShiftRng, RAND_BENCH_N};
use super::Exp;
use distributions::Sample;
#[bench]
fn rand_exp(bh: &mut BenchHarness) {

View File

@ -10,9 +10,9 @@
//! The Gamma and derived distributions.
use num::Float;
use num;
use rand::{Rng, Open01};
use std::num::Float;
use std::num;
use {Rng, Open01};
use super::normal::StandardNormal;
use super::{IndependentSample, Sample, Exp};
@ -20,7 +20,7 @@ use super::{IndependentSample, Sample, Exp};
///
/// The density function of this distribution is
///
/// ```ignore
/// ```notrust
/// f(x) = x^(k - 1) * exp(-x / θ) / (Γ(k) * θ^k)
/// ```
///
@ -35,8 +35,7 @@ use super::{IndependentSample, Sample, Exp};
/// # Example
///
/// ```rust
/// use std::rand;
/// use std::rand::distributions::{IndependentSample, Gamma};
/// use rand::distributions::{IndependentSample, Gamma};
///
/// let gamma = Gamma::new(2.0, 5.0);
/// let v = gamma.ind_sample(&mut rand::task_rng());
@ -179,8 +178,7 @@ impl IndependentSample<f64> for GammaLargeShape {
/// # Example
///
/// ```rust
/// use std::rand;
/// use std::rand::distributions::{ChiSquared, IndependentSample};
/// use rand::distributions::{ChiSquared, IndependentSample};
///
/// let chi = ChiSquared::new(11.0);
/// let v = chi.ind_sample(&mut rand::task_rng());
@ -231,8 +229,7 @@ impl IndependentSample<f64> for ChiSquared {
/// # Example
///
/// ```rust
/// use std::rand;
/// use std::rand::distributions::{FisherF, IndependentSample};
/// use rand::distributions::{FisherF, IndependentSample};
///
/// let f = FisherF::new(2.0, 32.0);
/// let v = f.ind_sample(&mut rand::task_rng());
@ -275,8 +272,7 @@ impl IndependentSample<f64> for FisherF {
/// # Example
///
/// ```rust
/// use std::rand;
/// use std::rand::distributions::{StudentT, IndependentSample};
/// use rand::distributions::{StudentT, IndependentSample};
///
/// let t = StudentT::new(11.0);
/// let v = t.ind_sample(&mut rand::task_rng());
@ -310,10 +306,9 @@ impl IndependentSample<f64> for StudentT {
#[cfg(test)]
mod test {
use rand::distributions::*;
use prelude::*;
use rand::*;
use super::*;
use distributions::{Sample, IndependentSample};
use {Rng, task_rng};
use super::{ChiSquared, StudentT, FisherF};
#[test]
fn test_chi_squared_one() {
@ -344,7 +339,7 @@ mod test {
}
#[test]
#[should_fail]
fn test_log_normal_invalid_dof() {
fn test_chi_squared_invalid_dof() {
ChiSquared::new(-1.0);
}
@ -373,11 +368,10 @@ mod test {
mod bench {
extern crate test;
use self::test::BenchHarness;
use mem::size_of;
use prelude::*;
use rand::distributions::IndependentSample;
use rand::{StdRng, RAND_BENCH_N};
use super::*;
use std::mem::size_of;
use distributions::IndependentSample;
use {StdRng, RAND_BENCH_N};
use super::Gamma;
#[bench]

View File

@ -20,14 +20,9 @@ that do not need to record state.
*/
use container::Container;
use iter::{range, Iterator};
use option::{Some, None};
use num;
use num::CheckedAdd;
use rand::{Rng, Rand};
use clone::Clone;
use vec::MutableVector;
use std::num;
use std::num::CheckedAdd;
use {Rng, Rand};
pub use self::range::Range;
pub use self::gamma::{Gamma, ChiSquared, FisherF, StudentT};
@ -94,8 +89,7 @@ pub struct Weighted<T> {
/// # Example
///
/// ```rust
/// use std::rand;
/// use std::rand::distributions::{Weighted, WeightedChoice, IndependentSample};
/// use rand::distributions::{Weighted, WeightedChoice, IndependentSample};
///
/// let wc = WeightedChoice::new(~[Weighted { weight: 2, item: 'a' },
/// Weighted { weight: 4, item: 'b' },
@ -253,9 +247,8 @@ fn ziggurat<R:Rng>(
#[cfg(test)]
mod tests {
use prelude::*;
use rand::*;
use super::*;
use {task_rng, Rng, Rand};
use super::{RandSample, WeightedChoice, Weighted, Sample, IndependentSample};
#[deriving(Eq, Show)]
struct ConstRand(uint);

View File

@ -10,9 +10,9 @@
//! The normal and derived distributions.
use num::Float;
use rand::{Rng, Rand, Open01};
use rand::distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
use std::num::Float;
use {Rng, Rand, Open01};
use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
/// A wrapper around an `f64` to generate N(0, 1) random numbers
/// (a.k.a. a standard normal, or Gaussian).
@ -74,8 +74,7 @@ impl Rand for StandardNormal {
/// # Example
///
/// ```rust
/// use std::rand;
/// use std::rand::distributions::{Normal, IndependentSample};
/// use rand::distributions::{Normal, IndependentSample};
///
/// // mean 2, standard deviation 3
/// let normal = Normal::new(2.0, 3.0);
@ -117,8 +116,7 @@ impl IndependentSample<f64> for Normal {
/// # Example
///
/// ```rust
/// use std::rand;
/// use std::rand::distributions::{LogNormal, IndependentSample};
/// use rand::distributions::{LogNormal, IndependentSample};
///
/// // mean 2, standard deviation 3
/// let log_normal = LogNormal::new(2.0, 3.0);
@ -148,10 +146,9 @@ impl IndependentSample<f64> for LogNormal {
#[cfg(test)]
mod tests {
use prelude::*;
use rand::*;
use super::*;
use rand::distributions::*;
use distributions::{Sample, IndependentSample};
use {Rng, task_rng};
use super::{Normal, LogNormal};
#[test]
fn test_normal() {
@ -189,11 +186,10 @@ mod tests {
mod bench {
extern crate test;
use self::test::BenchHarness;
use mem::size_of;
use prelude::*;
use rand::{XorShiftRng, RAND_BENCH_N};
use rand::distributions::*;
use super::*;
use std::mem::size_of;
use {XorShiftRng, RAND_BENCH_N};
use distributions::{Sample};
use super::Normal;
#[bench]
fn rand_normal(bh: &mut BenchHarness) {

View File

@ -12,10 +12,9 @@
// this is surprisingly complicated to be both generic & correct
use cmp::Ord;
use num::Bounded;
use rand::Rng;
use rand::distributions::{Sample, IndependentSample};
use std::num::Bounded;
use Rng;
use distributions::{Sample, IndependentSample};
/// Sample values uniformly between two bounds.
///
@ -34,8 +33,7 @@ use rand::distributions::{Sample, IndependentSample};
/// # Example
///
/// ```rust
/// use std::rand;
/// use std::rand::distributions::{IndependentSample, Range};
/// use rand::distributions::{IndependentSample, Range};
///
/// fn main() {
/// let between = Range::new(10u, 10000u);
@ -163,11 +161,10 @@ float_impl! { f64 }
#[cfg(test)]
mod tests {
use prelude::*;
use super::*;
use rand::*;
use rand::distributions::*;
use num::Bounded;
use distributions::{Sample, IndependentSample};
use {Rng, task_rng};
use super::Range;
use std::num::Bounded;
#[should_fail]
#[test]

View File

@ -10,11 +10,10 @@
//! The ISAAC random number generator.
use rand::{Rng, SeedableRng, OSRng};
use iter::{Iterator, range, range_step, Repeat};
use option::{None, Some};
use vec::{raw, MutableVector, ImmutableVector};
use mem;
use {Rng, SeedableRng, OSRng};
use std::iter::{range_step, Repeat};
use std::vec::raw;
use std::mem;
static RAND_SIZE_LEN: u32 = 8;
static RAND_SIZE: u32 = 1 << RAND_SIZE_LEN;
@ -430,10 +429,9 @@ impl<'a> SeedableRng<&'a [u64]> for Isaac64Rng {
#[cfg(test)]
mod test {
use super::*;
use rand::{Rng, SeedableRng, OSRng};
use prelude::*;
use vec;
use super::{IsaacRng, Isaac64Rng};
use {Rng, SeedableRng, OSRng};
use std::vec;
#[test]
fn test_rng_32_rand_seeded() {

View File

@ -48,38 +48,41 @@ randomness.
# Examples
```rust
use std::rand;
use std::rand::Rng;
use rand::Rng;
let mut rng = rand::rng();
if rng.gen() { // bool
println!("int: {}, uint: {}", rng.gen::<int>(), rng.gen::<uint>())
}
```
```
```rust
use std::rand;
let tuple_ptr = rand::random::<~(f64, char)>();
println!("{:?}", tuple_ptr)
```
```
*/
use cast;
use cmp::Ord;
use container::Container;
use iter::{Iterator, range};
use kinds::marker;
use local_data;
use prelude::*;
use str;
use vec;
#[crate_id = "rand#0.10-pre"];
#[license = "MIT/ASL2"];
#[crate_type = "dylib"];
#[crate_type = "rlib"];
#[doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://static.rust-lang.org/doc/master")];
pub use self::isaac::{IsaacRng, Isaac64Rng};
pub use self::os::OSRng;
#[feature(macro_rules, managed_boxes)];
use self::distributions::{Range, IndependentSample};
use self::distributions::range::SampleRange;
use std::cast;
use std::kinds::marker;
use std::local_data;
use std::str;
use std::vec;
pub use isaac::{IsaacRng, Isaac64Rng};
pub use os::OSRng;
use distributions::{Range, IndependentSample};
use distributions::range::SampleRange;
pub mod distributions;
pub mod isaac;
@ -135,7 +138,7 @@ pub trait Rng {
/// # Example
///
/// ```rust
/// use std::rand::{task_rng, Rng};
/// use rand::{task_rng, Rng};
///
/// let mut v = [0u8, .. 13579];
/// task_rng().fill_bytes(v);
@ -170,7 +173,7 @@ pub trait Rng {
/// # Example
///
/// ```rust
/// use std::rand::{task_rng, Rng};
/// use rand::{task_rng, Rng};
///
/// let mut rng = task_rng();
/// let x: uint = rng.gen();
@ -187,7 +190,7 @@ pub trait Rng {
/// # Example
///
/// ```rust
/// use std::rand::{task_rng, Rng};
/// use rand::{task_rng, Rng};
///
/// let mut rng = task_rng();
/// let x: ~[uint] = rng.gen_vec(10);
@ -210,7 +213,7 @@ pub trait Rng {
/// # Example
///
/// ```rust
/// use std::rand::{task_rng, Rng};
/// use rand::{task_rng, Rng};
///
/// let mut rng = task_rng();
/// let n: uint = rng.gen_range(0u, 10);
@ -228,7 +231,7 @@ pub trait Rng {
/// # Example
///
/// ```rust
/// use std::rand::{task_rng, Rng};
/// use rand::{task_rng, Rng};
///
/// let mut rng = task_rng();
/// println!("{:b}", rng.gen_weighted_bool(3));
@ -243,7 +246,7 @@ pub trait Rng {
/// # Example
///
/// ```rust
/// use std::rand::{task_rng, Rng};
/// use rand::{task_rng, Rng};
///
/// println!("{}", task_rng().gen_ascii_str(10));
/// ```
@ -269,7 +272,7 @@ pub trait Rng {
/// # Example
///
/// ```rust
/// use std::rand::{task_rng, Rng};
/// use rand::{task_rng, Rng};
///
/// let choices = [1, 2, 4, 8, 16, 32];
/// let mut rng = task_rng();
@ -289,7 +292,7 @@ pub trait Rng {
/// # Example
///
/// ```rust
/// use std::rand::{task_rng, Rng};
/// use rand::{task_rng, Rng};
///
/// println!("{:?}", task_rng().shuffle(~[1,2,3]));
/// ```
@ -304,7 +307,7 @@ pub trait Rng {
/// # Example
///
/// ```rust
/// use std::rand::{task_rng, Rng};
/// use rand::{task_rng, Rng};
///
/// let mut rng = task_rng();
/// let mut y = [1,2,3];
@ -328,7 +331,7 @@ pub trait Rng {
/// # Example
///
/// ```rust
/// use std::rand::{task_rng, Rng};
/// use rand::{task_rng, Rng};
///
/// let mut rng = task_rng();
/// let sample = rng.sample(range(1, 100), 5);
@ -359,7 +362,7 @@ pub trait SeedableRng<Seed>: Rng {
/// # Example
///
/// ```rust
/// use std::rand::{Rng, SeedableRng, StdRng};
/// use rand::{Rng, SeedableRng, StdRng};
///
/// let mut rng: StdRng = SeedableRng::from_seed(&[1, 2, 3, 4]);
/// println!("{}", rng.gen::<f64>());
@ -373,7 +376,7 @@ pub trait SeedableRng<Seed>: Rng {
/// # Example
///
/// ```rust
/// use std::rand::{Rng, SeedableRng, StdRng};
/// use rand::{Rng, SeedableRng, StdRng};
///
/// let mut rng: StdRng = SeedableRng::from_seed(&[1, 2, 3, 4]);
/// println!("{}", rng.gen::<f64>());
@ -609,7 +612,7 @@ impl Rng for TaskRng {
/// # Example
///
/// ```rust
/// use std::rand::random;
/// use rand::random;
///
/// if random() {
/// let x = random();
@ -631,8 +634,8 @@ pub fn random<T: Rand>() -> T {
/// `[0,1)`.
///
/// # Example
/// ```rust,ignore
/// use std::rand::{random, Open01};
/// ```rust
/// use rand::{random, Open01};
///
/// let Open01(val) = random::<Open01<f32>>();
/// println!("f32 from (0,1): {}", val);
@ -647,8 +650,8 @@ pub struct Open01<F>(F);
/// `[0,1)`.
///
/// # Example
/// ```rust,ignore
/// use std::rand::{random, Closed01};
/// ```rust
/// use rand::{random, Closed01};
///
/// let Closed01(val) = random::<Closed01<f32>>();
/// println!("f32 from [0,1]: {}", val);
@ -657,9 +660,8 @@ pub struct Closed01<F>(F);
#[cfg(test)]
mod test {
use prelude::*;
use vec;
use super::*;
use std::vec;
use super::{Rng, task_rng, random, OSRng, SeedableRng, StdRng};
struct ConstRng { i: u64 }
impl Rng for ConstRng {
@ -691,7 +693,7 @@ mod test {
#[test]
fn test_gen_range() {
let mut r = rng();
let mut r = task_rng();
for _ in range(0, 1000) {
let a = r.gen_range(-3i, 42);
assert!(a >= -3 && a < 42);
@ -711,20 +713,20 @@ mod test {
#[test]
#[should_fail]
fn test_gen_range_fail_int() {
let mut r = rng();
let mut r = task_rng();
r.gen_range(5i, -2);
}
#[test]
#[should_fail]
fn test_gen_range_fail_uint() {
let mut r = rng();
let mut r = task_rng();
r.gen_range(5u, 2u);
}
#[test]
fn test_gen_f64() {
let mut r = rng();
let mut r = task_rng();
let a = r.gen::<f64>();
let b = r.gen::<f64>();
debug!("{:?}", (a, b));
@ -732,14 +734,14 @@ mod test {
#[test]
fn test_gen_weighted_bool() {
let mut r = rng();
let mut r = task_rng();
assert_eq!(r.gen_weighted_bool(0u), true);
assert_eq!(r.gen_weighted_bool(1u), true);
}
#[test]
fn test_gen_ascii_str() {
let mut r = rng();
let mut r = task_rng();
debug!("{}", r.gen_ascii_str(10u));
debug!("{}", r.gen_ascii_str(10u));
debug!("{}", r.gen_ascii_str(10u));
@ -750,7 +752,7 @@ mod test {
#[test]
fn test_gen_vec() {
let mut r = rng();
let mut r = task_rng();
assert_eq!(r.gen_vec::<u8>(0u).len(), 0u);
assert_eq!(r.gen_vec::<u8>(10u).len(), 10u);
assert_eq!(r.gen_vec::<f64>(16u).len(), 16u);
@ -758,13 +760,13 @@ mod test {
#[test]
fn test_choose() {
let mut r = rng();
let mut r = task_rng();
assert_eq!(r.choose([1, 1, 1]), 1);
}
#[test]
fn test_choose_option() {
let mut r = rng();
let mut r = task_rng();
let v: &[int] = &[];
assert!(r.choose_option(v).is_none());
@ -775,7 +777,7 @@ mod test {
#[test]
fn test_shuffle() {
let mut r = rng();
let mut r = task_rng();
let empty: ~[int] = ~[];
assert_eq!(r.shuffle(~[]), empty);
assert_eq!(r.shuffle(~[1, 1, 1]), ~[1, 1, 1]);
@ -806,7 +808,7 @@ mod test {
let min_val = 1;
let max_val = 100;
let mut r = rng();
let mut r = task_rng();
let vals = range(min_val, max_val).to_owned_vec();
let small_sample = r.sample(vals.iter(), 5);
let large_sample = r.sample(vals.iter(), vals.len() + 5);
@ -847,9 +849,8 @@ static RAND_BENCH_N: u64 = 100;
mod bench {
extern crate test;
use self::test::BenchHarness;
use prelude::*;
use rand::{XorShiftRng, StdRng, IsaacRng, Isaac64Rng, Rng, RAND_BENCH_N};
use mem::size_of;
use {XorShiftRng, StdRng, IsaacRng, Isaac64Rng, Rng, RAND_BENCH_N};
use std::mem::size_of;
#[bench]
fn rand_xorshift(bh: &mut BenchHarness) {

View File

@ -11,18 +11,17 @@
//! Interfaces to the operating system provided random number
//! generators.
use rand::Rng;
use ops::Drop;
use Rng;
#[cfg(unix)]
use rand::reader::ReaderRng;
use reader::ReaderRng;
#[cfg(unix)]
use io::File;
use std::io::File;
#[cfg(windows)]
use cast;
use std::cast;
#[cfg(windows)]
use libc::{c_long, DWORD, BYTE};
use std::libc::{c_long, DWORD, BYTE};
#[cfg(windows)]
type HCRYPTPROV = c_long;
// the extern functions imported from the runtime on Windows are
@ -60,7 +59,6 @@ impl OSRng {
/// Create a new `OSRng`.
#[cfg(unix)]
pub fn new() -> OSRng {
use path::Path;
let reader = File::open(&Path::new("/dev/urandom"));
let reader = reader.ok().expect("Error opening /dev/urandom");
let reader_rng = ReaderRng::new(reader);
@ -106,9 +104,6 @@ impl Rng for OSRng {
unsafe { cast::transmute(v) }
}
fn fill_bytes(&mut self, v: &mut [u8]) {
use container::Container;
use vec::MutableVector;
extern {
fn rust_win32_rand_gen(hProv: HCRYPTPROV, dwLen: DWORD,
pbBuffer: *mut BYTE);
@ -136,10 +131,9 @@ impl Drop for OSRng {
#[cfg(test)]
mod test {
use prelude::*;
use super::*;
use rand::Rng;
use task;
use super::OSRng;
use Rng;
use std::task;
#[test]
fn test_os_rng() {

View File

@ -10,11 +10,11 @@
//! The implementations of `Rand` for the built-in types.
use char;
use int;
use option::{Option, Some, None};
use rand::{Rand,Rng};
use uint;
use std::char;
use std::int;
use std::uint;
use {Rand,Rng};
impl Rand for int {
#[inline]
@ -97,7 +97,7 @@ impl Rand for u64 {
macro_rules! float_impls {
($mod_name:ident, $ty:ty, $mantissa_bits:expr, $method_name:ident, $ignored_bits:expr) => {
mod $mod_name {
use rand::{Rand, Rng, Open01, Closed01};
use {Rand, Rng, Open01, Closed01};
static SCALE: $ty = (1u64 << $mantissa_bits) as $ty;
@ -226,8 +226,7 @@ impl<T: Rand + 'static> Rand for @T {
#[cfg(test)]
mod tests {
use prelude::*;
use rand::{Rng, task_rng, Open01, Closed01};
use {Rng, task_rng, Open01, Closed01};
struct ConstantRng(u64);
impl Rng for ConstantRng {

View File

@ -10,11 +10,7 @@
//! A wrapper around any Reader to treat it as an RNG.
use container::Container;
use result::{Ok, Err};
use io::Reader;
use rand::Rng;
use Rng;
/// An RNG that reads random bytes straight from a `Reader`. This will
/// work best with an infinite reader, but this is not required.
@ -24,7 +20,7 @@ use rand::Rng;
/// # Example
///
/// ```rust
/// use std::rand::{reader, Rng};
/// use rand::{reader, Rng};
/// use std::io::MemReader;
///
/// let mut rng = reader::ReaderRng::new(MemReader::new(~[1,2,3,4,5,6,7,8]));
@ -75,11 +71,10 @@ impl<R: Reader> Rng for ReaderRng<R> {
#[cfg(test)]
mod test {
use super::*;
use io::MemReader;
use cast;
use rand::*;
use prelude::*;
use super::ReaderRng;
use std::io::MemReader;
use std::cast;
use Rng;
#[test]
fn test_reader_rng_u64() {

View File

@ -11,9 +11,8 @@
//! A wrapper around another RNG that reseeds it after it
//! generates a certain number of random bytes.
use container::Container;
use default::Default;
use rand::{Rng, SeedableRng};
use std::default::Default;
use {Rng, SeedableRng};
/// How many bytes of entropy the underling RNG is allowed to generate
/// before it is reseeded.
@ -101,9 +100,8 @@ impl<S, R: SeedableRng<S>, Rsdr: Reseeder<R>>
/// # Example
///
/// ```rust
/// use std::rand;
/// use std::rand::{Rng, SeedableRng};
/// use std::rand::reseeding::{Reseeder, ReseedingRng};
/// use rand::{Rng, SeedableRng};
/// use rand::reseeding::{Reseeder, ReseedingRng};
///
/// struct TickTockReseeder { tick: bool }
/// impl Reseeder<rand::StdRng> for TickTockReseeder {
@ -142,10 +140,9 @@ impl Default for ReseedWithDefault {
#[cfg(test)]
mod test {
use prelude::*;
use super::*;
use default::Default;
use rand::{SeedableRng, Rng};
use super::{ReseedingRng, ReseedWithDefault};
use std::default::Default;
use {SeedableRng, Rng};
struct Counter {
i: u32
@ -205,7 +202,7 @@ mod test {
static fill_bytes_v_len: uint = 13579;
#[test]
fn test_rng_fill_bytes() {
use rand::task_rng;
use task_rng;
let mut v = ~[0u8, .. fill_bytes_v_len];
task_rng().fill_bytes(v);

View File

@ -73,7 +73,8 @@
#[cfg(test)] extern crate native;
#[cfg(test)] extern crate green;
// Make extra accessible for benchmarking
// Make extra and rand accessible for benchmarking/testcases
#[cfg(test)] extern crate rand;
#[cfg(test)] extern crate extra = "extra";
// Make std testable by not duplicating lang items. See #2912
@ -173,7 +174,6 @@ pub mod c_str;
pub mod os;
pub mod io;
pub mod path;
pub mod rand;
pub mod cast;
pub mod fmt;
pub mod cleanup;

View File

@ -26,7 +26,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt,
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
path: Path::new(vec!("std", "rand", "Rand")),
path: Path::new(vec!("rand", "Rand")),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
methods: vec!(
@ -35,7 +35,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt,
generics: LifetimeBounds {
lifetimes: Vec::new(),
bounds: vec!(("R",
vec!( Path::new(vec!("std", "rand", "Rng")) )))
vec!( Path::new(vec!("rand", "Rng")) )))
},
explicit_self: None,
args: vec!(
@ -58,7 +58,6 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
_ => cx.bug("Incorrect number of arguments to `rand` in `deriving(Rand)`")
};
let rand_ident = vec!(
cx.ident_of("std"),
cx.ident_of("rand"),
cx.ident_of("Rand"),
cx.ident_of("rand")
@ -89,7 +88,7 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
Vec::new());
let rand_name = cx.expr_path(rand_name);
// ::std::rand::Rand::rand(rng)
// ::rand::Rand::rand(rng)
let rv_call = cx.expr_call(trait_span,
rand_name,
vec!( *rng.get(0) ));

View File

@ -410,7 +410,7 @@ rust_win32_rand_acquire(HCRYPTPROV* phProv) {
win32_require
(_T("CryptAcquireContext"),
// changes to the parameters here should be reflected in the docs of
// std::rand::os::OSRng
// rand::os::OSRng
CryptAcquireContext(phProv, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT|CRYPT_SILENT));

View File

@ -10,9 +10,11 @@
// ensure that the TaskRng isn't/doesn't become accidentally sendable.
extern crate rand;
fn test_send<S: Send>() {}
pub fn main() {
test_send::<::std::rand::TaskRng>();
//~^ ERROR: incompatible type `std::rand::TaskRng`, which does not fulfill `Send`
test_send::<::rand::TaskRng>();
//~^ ERROR: incompatible type `rand::TaskRng`, which does not fulfill `Send`
}