Skip to content

Move std::rand to a separate rand crate #12650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/doc/guide-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ concurrency at this writing:
* [`sync::DuplexStream`] - An extension of `pipes::stream` that allows both sending and receiving,
* [`sync::SyncChan`] - An extension of `pipes::stream` that provides synchronous message sending,
* [`sync::SyncPort`] - An extension of `pipes::stream` that acknowledges each message received,
* [`sync::rendezvous`] - Creates a stream whose channel, upon sending a message, blocks until the
* [`sync::rendezvous`] - Creates a stream whose channel, upon sending a message, blocks until the
message is received.
* [`sync::Arc`] - The Arc (atomically reference counted) type, for safely sharing immutable data,
* [`sync::RWArc`] - A dual-mode Arc protected by a reader-writer lock,
* [`sync::MutexArc`] - An Arc with mutable data protected by a blocking mutex,
* [`sync::Semaphore`] - A counting, blocking, bounded-waiting semaphore,
* [`sync::Mutex`] - A blocking, bounded-waiting, mutual exclusion lock with an associated
* [`sync::Mutex`] - A blocking, bounded-waiting, mutual exclusion lock with an associated
FIFO condition variable,
* [`sync::RWLock`] - A blocking, no-starvation, reader-writer lock with an associated condvar,
* [`sync::Barrier`] - A barrier enables multiple tasks to synchronize the beginning
Expand Down Expand Up @@ -343,8 +343,8 @@ a single large vector of floats. Each task needs the full vector to perform its

~~~
# extern crate sync;
extern crate rand;
# use std::vec;
# use std::rand;
use sync::Arc;

fn pnorm(nums: &~[f64], p: uint) -> f64 {
Expand Down Expand Up @@ -376,9 +376,9 @@ created by the line

~~~
# extern crate sync;
# extern crate rand;
# use sync::Arc;
# use std::vec;
# use std::rand;
# fn main() {
# let numbers = vec::from_fn(1000000, |_| rand::random::<f64>());
let numbers_arc=Arc::new(numbers);
Expand All @@ -389,9 +389,9 @@ and a clone of it is sent to each task

~~~
# extern crate sync;
# extern crate rand;
# use sync::Arc;
# use std::vec;
# use std::rand;
# fn main() {
# let numbers=vec::from_fn(1000000, |_| rand::random::<f64>());
# let numbers_arc = Arc::new(numbers);
Expand All @@ -406,9 +406,9 @@ Each task recovers the underlying data by

~~~
# extern crate sync;
# extern crate rand;
# use sync::Arc;
# use std::vec;
# use std::rand;
# fn main() {
# let numbers=vec::from_fn(1000000, |_| rand::random::<f64>());
# let numbers_arc=Arc::new(numbers);
Expand Down
2 changes: 1 addition & 1 deletion src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2529,7 +2529,7 @@ of type `ABC` can be randomly generated and converted to a string:
#[deriving(Eq)]
struct Circle { radius: f64 }

#[deriving(Rand, Show)]
#[deriving(Clone, Show)]
enum ABC { A, B, C }
~~~

Expand Down
1 change: 1 addition & 0 deletions src/etc/generate-deriving-span-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#[feature(struct_variant)];
extern crate extra;
extern crate rand;

{error_deriving}
struct Error;
Expand Down
2 changes: 1 addition & 1 deletion src/etc/ziggurat_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,8 @@ mod tests {

use std::uint;
use std::vec;
use std::rand;
use std::rand::Rng;
use rand;
use rand::Rng;

static BENCH_BITS : uint = 1 << 14;

Expand Down
5 changes: 3 additions & 2 deletions src/libcollections/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ pub mod bench {
extern crate test;
use self::test::BenchHarness;
use std::container::MutableMap;
use std::{vec, rand};
use std::rand::Rng;
use std::vec;
use rand;
use rand::Rng;

pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ mod tests {
extern crate test;
use self::test::BenchHarness;
use deque::Deque;
use std::rand;
use rand;
use super::{DList, Node, ListInsertion};

pub fn check_links<T>(list: &DList<T>) {
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ use std::iter::{FilterMap, Chain, Repeat, Zip};
use std::iter;
use std::mem::replace;
use std::num;
use std::rand::Rng;
use std::rand;
use rand::Rng;
use rand;
use std::vec::{Items, MutItems};
use std::vec_ng::Vec;
use std::vec_ng;
Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#[allow(unrecognized_lint)];
#[allow(default_type_param_usage)];

extern crate rand;

#[cfg(test)] extern crate test;

pub use bitv::Bitv;
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,8 @@ mod test_treemap {

use super::{TreeMap, TreeNode};

use std::rand::Rng;
use std::rand;
use rand::Rng;
use rand;

#[test]
fn find_empty() {
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ mod test_map {
mod bench_map {
extern crate test;
use super::TrieMap;
use std::rand::{weak_rng, Rng};
use rand::{weak_rng, Rng};
use self::test::BenchHarness;

#[bench]
Expand Down
5 changes: 3 additions & 2 deletions src/libextra/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ Rust extras are part of the standard Rust distribution.
#[deny(non_camel_case_types)];
#[deny(missing_doc)];

extern crate sync;
extern crate serialize;
extern crate collections;
extern crate rand;
extern crate serialize;
extern crate sync;
extern crate time;

// Utility modules
Expand Down
5 changes: 2 additions & 3 deletions src/libextra/tempfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@


use std::os;
use std::rand::Rng;
use std::rand;
use rand::{task_rng, Rng};
use std::io;
use std::io::fs;

Expand All @@ -35,7 +34,7 @@ impl TempDir {
return TempDir::new_in(&abs_tmpdir, suffix);
}

let mut r = rand::rng();
let mut r = task_rng();
for _ in range(0u, 1000) {
let p = tmpdir.join(r.gen_ascii_str(16) + suffix);
match fs::mkdir(&p, io::UserRWX) {
Expand Down
7 changes: 4 additions & 3 deletions src/libflate/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ pub fn inflate_bytes_zlib(bytes: &[u8]) -> CVec<u8> {

#[cfg(test)]
mod tests {
extern crate rand;

use super::{inflate_bytes, deflate_bytes};
use std::rand;
use std::rand::Rng;
use self::rand::Rng;

#[test]
fn test_flate_round_trip() {
let mut r = rand::rng();
let mut r = rand::task_rng();
let mut words = ~[];
for _ in range(0, 20) {
let range = r.gen_range(1u, 10);
Expand Down
2 changes: 2 additions & 0 deletions src/libgreen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@
#[feature(macro_rules)];
#[allow(visible_private_types)];

extern crate rand;

use std::mem::replace;
use std::os;
use std::rt::crate_map;
Expand Down
5 changes: 3 additions & 2 deletions src/libgreen/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

use std::cast;
use std::rand::{XorShiftRng, Rng, Rand};
use std::rt::local::Local;
use std::rt::rtio::{RemoteCallback, PausableIdleCallback, Callback, EventLoop};
use std::rt::task::BlockedTask;
Expand All @@ -18,6 +17,8 @@ use std::sync::deque;
use std::unstable::mutex::NativeMutex;
use std::raw;

use rand::{XorShiftRng, Rng, Rand};

use TaskState;
use context::Context;
use coroutine::Coroutine;
Expand Down Expand Up @@ -957,7 +958,7 @@ fn new_sched_rng() -> XorShiftRng {
fn new_sched_rng() -> XorShiftRng {
use std::libc;
use std::mem;
use std::rand::SeedableRng;
use rand::SeedableRng;

let fd = "/dev/urandom".with_c_str(|name| {
unsafe { libc::open(name, libc::O_RDONLY, 0) }
Expand Down
6 changes: 3 additions & 3 deletions src/libnum/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::from_str::FromStr;
use std::num::CheckedDiv;
use std::num::{Bitwise, ToPrimitive, FromPrimitive};
use std::num::{Zero, One, ToStrRadix, FromStrRadix};
use std::rand::Rng;
use rand::Rng;
use std::str;
use std::uint;
use std::vec;
Expand Down Expand Up @@ -1470,7 +1470,7 @@ mod biguint_tests {
use std::num::{Zero, One, FromStrRadix, ToStrRadix};
use std::num::{ToPrimitive, FromPrimitive};
use std::num::CheckedDiv;
use std::rand::{task_rng};
use rand::{task_rng};
use std::str;
use std::u64;
use std::vec;
Expand Down Expand Up @@ -2205,7 +2205,7 @@ mod bigint_tests {
use std::num::CheckedDiv;
use std::num::{Zero, One, FromStrRadix, ToStrRadix};
use std::num::{ToPrimitive, FromPrimitive};
use std::rand::{task_rng};
use rand::{task_rng};
use std::u64;

#[test]
Expand Down
2 changes: 2 additions & 0 deletions src/libnum/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#[crate_type = "dylib"];
#[license = "MIT/ASL2"];

extern crate rand;

pub mod bigint;
pub mod rational;
pub mod complex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
Loading