Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6fa4bbe

Browse files
committedMar 12, 2014
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.
1 parent 74bfa71 commit 6fa4bbe

File tree

18 files changed

+161
-198
lines changed

18 files changed

+161
-198
lines changed
 

‎mk/crates.mk

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@
5050
################################################################################
5151

5252
TARGET_CRATES := std extra green rustuv native flate arena glob term semver \
53-
uuid serialize sync getopts collections num test time
53+
uuid serialize sync getopts collections num test time rand
5454
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat
5555
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
5656
TOOLS := compiletest rustdoc rustc
5757

5858
DEPS_std := native:rustrt native:compiler-rt
59-
DEPS_extra := std term sync serialize getopts collections time
60-
DEPS_green := std native:context_switch
59+
DEPS_extra := std term sync serialize getopts collections time rand
60+
DEPS_green := std rand native:context_switch
6161
DEPS_rustuv := std native:uv native:uv_support
6262
DEPS_native := std
6363
DEPS_syntax := std term serialize collections
@@ -71,15 +71,16 @@ DEPS_glob := std
7171
DEPS_serialize := std collections
7272
DEPS_term := std collections
7373
DEPS_semver := std
74-
DEPS_uuid := std serialize
74+
DEPS_uuid := std serialize rand
7575
DEPS_sync := std
7676
DEPS_getopts := std
77-
DEPS_collections := std
77+
DEPS_collections := std rand
7878
DEPS_fourcc := syntax std
7979
DEPS_hexfloat := syntax std
80-
DEPS_num := std
80+
DEPS_num := std rand
8181
DEPS_test := std extra collections getopts serialize term
8282
DEPS_time := std serialize
83+
DEPS_rand := std
8384

8485
TOOL_DEPS_compiletest := test green rustuv getopts
8586
TOOL_DEPS_rustdoc := rustdoc native

‎src/etc/ziggurat_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# except according to those terms.
1212

1313
# This creates the tables used for distributions implemented using the
14-
# ziggurat algorithm in `std::rand::distributions;`. They are
14+
# ziggurat algorithm in `rand::distributions;`. They are
1515
# (basically) the tables as used in the ZIGNOR variant (Doornik 2005).
1616
# They are changed rarely, so the generated file should be checked in
1717
# to git.

‎src/libstd/rand/distributions/exponential.rs renamed to ‎src/librand/distributions/exponential.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
//! The exponential distribution.
1212
13-
use num::Float;
14-
use rand::{Rng, Rand};
15-
use rand::distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
13+
use std::num::Float;
14+
use {Rng, Rand};
15+
use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
1616

1717
/// A wrapper around an `f64` to generate Exp(1) random numbers.
1818
///
@@ -58,8 +58,7 @@ impl Rand for Exp1 {
5858
/// # Example
5959
///
6060
/// ```rust
61-
/// use std::rand;
62-
/// use std::rand::distributions::{Exp, IndependentSample};
61+
/// use rand::distributions::{Exp, IndependentSample};
6362
///
6463
/// let exp = Exp::new(2.0);
6564
/// let v = exp.ind_sample(&mut rand::task_rng());
@@ -91,10 +90,9 @@ impl IndependentSample<f64> for Exp {
9190

9291
#[cfg(test)]
9392
mod test {
94-
use rand::distributions::*;
95-
use prelude::*;
96-
use rand::*;
97-
use super::*;
93+
use distributions::{Sample, IndependentSample};
94+
use {Rng, task_rng};
95+
use super::Exp;
9896

9997
#[test]
10098
fn test_exp() {
@@ -121,11 +119,10 @@ mod test {
121119
mod bench {
122120
extern crate test;
123121
use self::test::BenchHarness;
124-
use mem::size_of;
125-
use prelude::*;
126-
use rand::{XorShiftRng, RAND_BENCH_N};
127-
use super::*;
128-
use rand::distributions::*;
122+
use std::mem::size_of;
123+
use {XorShiftRng, RAND_BENCH_N};
124+
use super::Exp;
125+
use distributions::Sample;
129126

130127
#[bench]
131128
fn rand_exp(bh: &mut BenchHarness) {

‎src/libstd/rand/distributions/gamma.rs renamed to ‎src/librand/distributions/gamma.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
//! The Gamma and derived distributions.
1212
13-
use num::Float;
14-
use num;
15-
use rand::{Rng, Open01};
13+
use std::num::Float;
14+
use std::num;
15+
use {Rng, Open01};
1616
use super::normal::StandardNormal;
1717
use super::{IndependentSample, Sample, Exp};
1818

1919
/// The Gamma distribution `Gamma(shape, scale)` distribution.
2020
///
2121
/// The density function of this distribution is
2222
///
23-
/// ```ignore
23+
/// ```notrust
2424
/// f(x) = x^(k - 1) * exp(-x / θ) / (Γ(k) * θ^k)
2525
/// ```
2626
///
@@ -35,8 +35,7 @@ use super::{IndependentSample, Sample, Exp};
3535
/// # Example
3636
///
3737
/// ```rust
38-
/// use std::rand;
39-
/// use std::rand::distributions::{IndependentSample, Gamma};
38+
/// use rand::distributions::{IndependentSample, Gamma};
4039
///
4140
/// let gamma = Gamma::new(2.0, 5.0);
4241
/// let v = gamma.ind_sample(&mut rand::task_rng());
@@ -179,8 +178,7 @@ impl IndependentSample<f64> for GammaLargeShape {
179178
/// # Example
180179
///
181180
/// ```rust
182-
/// use std::rand;
183-
/// use std::rand::distributions::{ChiSquared, IndependentSample};
181+
/// use rand::distributions::{ChiSquared, IndependentSample};
184182
///
185183
/// let chi = ChiSquared::new(11.0);
186184
/// let v = chi.ind_sample(&mut rand::task_rng());
@@ -231,8 +229,7 @@ impl IndependentSample<f64> for ChiSquared {
231229
/// # Example
232230
///
233231
/// ```rust
234-
/// use std::rand;
235-
/// use std::rand::distributions::{FisherF, IndependentSample};
232+
/// use rand::distributions::{FisherF, IndependentSample};
236233
///
237234
/// let f = FisherF::new(2.0, 32.0);
238235
/// let v = f.ind_sample(&mut rand::task_rng());
@@ -275,8 +272,7 @@ impl IndependentSample<f64> for FisherF {
275272
/// # Example
276273
///
277274
/// ```rust
278-
/// use std::rand;
279-
/// use std::rand::distributions::{StudentT, IndependentSample};
275+
/// use rand::distributions::{StudentT, IndependentSample};
280276
///
281277
/// let t = StudentT::new(11.0);
282278
/// let v = t.ind_sample(&mut rand::task_rng());
@@ -310,10 +306,9 @@ impl IndependentSample<f64> for StudentT {
310306

311307
#[cfg(test)]
312308
mod test {
313-
use rand::distributions::*;
314-
use prelude::*;
315-
use rand::*;
316-
use super::*;
309+
use distributions::{Sample, IndependentSample};
310+
use {Rng, task_rng};
311+
use super::{ChiSquared, StudentT, FisherF};
317312

318313
#[test]
319314
fn test_chi_squared_one() {
@@ -344,7 +339,7 @@ mod test {
344339
}
345340
#[test]
346341
#[should_fail]
347-
fn test_log_normal_invalid_dof() {
342+
fn test_chi_squared_invalid_dof() {
348343
ChiSquared::new(-1.0);
349344
}
350345

@@ -373,11 +368,10 @@ mod test {
373368
mod bench {
374369
extern crate test;
375370
use self::test::BenchHarness;
376-
use mem::size_of;
377-
use prelude::*;
378-
use rand::distributions::IndependentSample;
379-
use rand::{StdRng, RAND_BENCH_N};
380-
use super::*;
371+
use std::mem::size_of;
372+
use distributions::IndependentSample;
373+
use {StdRng, RAND_BENCH_N};
374+
use super::Gamma;
381375

382376

383377
#[bench]

‎src/libstd/rand/distributions/mod.rs renamed to ‎src/librand/distributions/mod.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@ that do not need to record state.
2020
2121
*/
2222

23-
use container::Container;
24-
use iter::{range, Iterator};
25-
use option::{Some, None};
26-
use num;
27-
use num::CheckedAdd;
28-
use rand::{Rng, Rand};
29-
use clone::Clone;
30-
use vec::MutableVector;
23+
use std::num;
24+
use std::num::CheckedAdd;
25+
use {Rng, Rand};
3126

3227
pub use self::range::Range;
3328
pub use self::gamma::{Gamma, ChiSquared, FisherF, StudentT};
@@ -94,8 +89,7 @@ pub struct Weighted<T> {
9489
/// # Example
9590
///
9691
/// ```rust
97-
/// use std::rand;
98-
/// use std::rand::distributions::{Weighted, WeightedChoice, IndependentSample};
92+
/// use rand::distributions::{Weighted, WeightedChoice, IndependentSample};
9993
///
10094
/// let wc = WeightedChoice::new(~[Weighted { weight: 2, item: 'a' },
10195
/// Weighted { weight: 4, item: 'b' },
@@ -253,9 +247,8 @@ fn ziggurat<R:Rng>(
253247

254248
#[cfg(test)]
255249
mod tests {
256-
use prelude::*;
257-
use rand::*;
258-
use super::*;
250+
use {task_rng, Rng, Rand};
251+
use super::{RandSample, WeightedChoice, Weighted, Sample, IndependentSample};
259252

260253
#[deriving(Eq, Show)]
261254
struct ConstRand(uint);

‎src/libstd/rand/distributions/normal.rs renamed to ‎src/librand/distributions/normal.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
//! The normal and derived distributions.
1212
13-
use num::Float;
14-
use rand::{Rng, Rand, Open01};
15-
use rand::distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
13+
use std::num::Float;
14+
use {Rng, Rand, Open01};
15+
use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
1616

1717
/// A wrapper around an `f64` to generate N(0, 1) random numbers
1818
/// (a.k.a. a standard normal, or Gaussian).
@@ -74,8 +74,7 @@ impl Rand for StandardNormal {
7474
/// # Example
7575
///
7676
/// ```rust
77-
/// use std::rand;
78-
/// use std::rand::distributions::{Normal, IndependentSample};
77+
/// use rand::distributions::{Normal, IndependentSample};
7978
///
8079
/// // mean 2, standard deviation 3
8180
/// let normal = Normal::new(2.0, 3.0);
@@ -117,8 +116,7 @@ impl IndependentSample<f64> for Normal {
117116
/// # Example
118117
///
119118
/// ```rust
120-
/// use std::rand;
121-
/// use std::rand::distributions::{LogNormal, IndependentSample};
119+
/// use rand::distributions::{LogNormal, IndependentSample};
122120
///
123121
/// // mean 2, standard deviation 3
124122
/// let log_normal = LogNormal::new(2.0, 3.0);
@@ -148,10 +146,9 @@ impl IndependentSample<f64> for LogNormal {
148146

149147
#[cfg(test)]
150148
mod tests {
151-
use prelude::*;
152-
use rand::*;
153-
use super::*;
154-
use rand::distributions::*;
149+
use distributions::{Sample, IndependentSample};
150+
use {Rng, task_rng};
151+
use super::{Normal, LogNormal};
155152

156153
#[test]
157154
fn test_normal() {
@@ -189,11 +186,10 @@ mod tests {
189186
mod bench {
190187
extern crate test;
191188
use self::test::BenchHarness;
192-
use mem::size_of;
193-
use prelude::*;
194-
use rand::{XorShiftRng, RAND_BENCH_N};
195-
use rand::distributions::*;
196-
use super::*;
189+
use std::mem::size_of;
190+
use {XorShiftRng, RAND_BENCH_N};
191+
use distributions::{Sample};
192+
use super::Normal;
197193

198194
#[bench]
199195
fn rand_normal(bh: &mut BenchHarness) {

‎src/libstd/rand/distributions/range.rs renamed to ‎src/librand/distributions/range.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
1313
// this is surprisingly complicated to be both generic & correct
1414

15-
use cmp::Ord;
16-
use num::Bounded;
17-
use rand::Rng;
18-
use rand::distributions::{Sample, IndependentSample};
15+
use std::num::Bounded;
16+
use Rng;
17+
use distributions::{Sample, IndependentSample};
1918

2019
/// Sample values uniformly between two bounds.
2120
///
@@ -34,8 +33,7 @@ use rand::distributions::{Sample, IndependentSample};
3433
/// # Example
3534
///
3635
/// ```rust
37-
/// use std::rand;
38-
/// use std::rand::distributions::{IndependentSample, Range};
36+
/// use rand::distributions::{IndependentSample, Range};
3937
///
4038
/// fn main() {
4139
/// let between = Range::new(10u, 10000u);
@@ -163,11 +161,10 @@ float_impl! { f64 }
163161

164162
#[cfg(test)]
165163
mod tests {
166-
use prelude::*;
167-
use super::*;
168-
use rand::*;
169-
use rand::distributions::*;
170-
use num::Bounded;
164+
use distributions::{Sample, IndependentSample};
165+
use {Rng, task_rng};
166+
use super::Range;
167+
use std::num::Bounded;
171168

172169
#[should_fail]
173170
#[test]

‎src/libstd/rand/isaac.rs renamed to ‎src/librand/isaac.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010

1111
//! The ISAAC random number generator.
1212
13-
use rand::{Rng, SeedableRng, OSRng};
14-
use iter::{Iterator, range, range_step, Repeat};
15-
use option::{None, Some};
16-
use vec::{raw, MutableVector, ImmutableVector};
17-
use mem;
13+
use {Rng, SeedableRng, OSRng};
14+
use std::iter::{range_step, Repeat};
15+
use std::vec::raw;
16+
use std::mem;
1817

1918
static RAND_SIZE_LEN: u32 = 8;
2019
static RAND_SIZE: u32 = 1 << RAND_SIZE_LEN;
@@ -430,10 +429,9 @@ impl<'a> SeedableRng<&'a [u64]> for Isaac64Rng {
430429

431430
#[cfg(test)]
432431
mod test {
433-
use super::*;
434-
use rand::{Rng, SeedableRng, OSRng};
435-
use prelude::*;
436-
use vec;
432+
use super::{IsaacRng, Isaac64Rng};
433+
use {Rng, SeedableRng, OSRng};
434+
use std::vec;
437435

438436
#[test]
439437
fn test_rng_32_rand_seeded() {

‎src/libstd/rand/mod.rs renamed to ‎src/librand/lib.rs

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,41 @@ randomness.
4848
# Examples
4949
5050
```rust
51-
use std::rand;
52-
use std::rand::Rng;
51+
use rand::Rng;
5352
5453
let mut rng = rand::rng();
5554
if rng.gen() { // bool
5655
println!("int: {}, uint: {}", rng.gen::<int>(), rng.gen::<uint>())
5756
}
58-
```
57+
```
5958
6059
```rust
61-
use std::rand;
62-
6360
let tuple_ptr = rand::random::<~(f64, char)>();
6461
println!("{:?}", tuple_ptr)
65-
```
62+
```
6663
*/
6764

68-
use cast;
69-
use cmp::Ord;
70-
use container::Container;
71-
use iter::{Iterator, range};
72-
use kinds::marker;
73-
use local_data;
74-
use prelude::*;
75-
use str;
76-
use vec;
65+
#[crate_id = "rand#0.10-pre"];
66+
#[license = "MIT/ASL2"];
67+
#[crate_type = "dylib"];
68+
#[crate_type = "rlib"];
69+
#[doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
70+
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
71+
html_root_url = "http://static.rust-lang.org/doc/master")];
72+
73+
#[feature(macro_rules, managed_boxes)];
7774

78-
pub use self::isaac::{IsaacRng, Isaac64Rng};
79-
pub use self::os::OSRng;
75+
use std::cast;
76+
use std::kinds::marker;
77+
use std::local_data;
78+
use std::str;
79+
use std::vec;
8080

81-
use self::distributions::{Range, IndependentSample};
82-
use self::distributions::range::SampleRange;
81+
pub use isaac::{IsaacRng, Isaac64Rng};
82+
pub use os::OSRng;
83+
84+
use distributions::{Range, IndependentSample};
85+
use distributions::range::SampleRange;
8386

8487
pub mod distributions;
8588
pub mod isaac;
@@ -135,7 +138,7 @@ pub trait Rng {
135138
/// # Example
136139
///
137140
/// ```rust
138-
/// use std::rand::{task_rng, Rng};
141+
/// use rand::{task_rng, Rng};
139142
///
140143
/// let mut v = [0u8, .. 13579];
141144
/// task_rng().fill_bytes(v);
@@ -170,7 +173,7 @@ pub trait Rng {
170173
/// # Example
171174
///
172175
/// ```rust
173-
/// use std::rand::{task_rng, Rng};
176+
/// use rand::{task_rng, Rng};
174177
///
175178
/// let mut rng = task_rng();
176179
/// let x: uint = rng.gen();
@@ -187,7 +190,7 @@ pub trait Rng {
187190
/// # Example
188191
///
189192
/// ```rust
190-
/// use std::rand::{task_rng, Rng};
193+
/// use rand::{task_rng, Rng};
191194
///
192195
/// let mut rng = task_rng();
193196
/// let x: ~[uint] = rng.gen_vec(10);
@@ -210,7 +213,7 @@ pub trait Rng {
210213
/// # Example
211214
///
212215
/// ```rust
213-
/// use std::rand::{task_rng, Rng};
216+
/// use rand::{task_rng, Rng};
214217
///
215218
/// let mut rng = task_rng();
216219
/// let n: uint = rng.gen_range(0u, 10);
@@ -228,7 +231,7 @@ pub trait Rng {
228231
/// # Example
229232
///
230233
/// ```rust
231-
/// use std::rand::{task_rng, Rng};
234+
/// use rand::{task_rng, Rng};
232235
///
233236
/// let mut rng = task_rng();
234237
/// println!("{:b}", rng.gen_weighted_bool(3));
@@ -243,7 +246,7 @@ pub trait Rng {
243246
/// # Example
244247
///
245248
/// ```rust
246-
/// use std::rand::{task_rng, Rng};
249+
/// use rand::{task_rng, Rng};
247250
///
248251
/// println!("{}", task_rng().gen_ascii_str(10));
249252
/// ```
@@ -269,7 +272,7 @@ pub trait Rng {
269272
/// # Example
270273
///
271274
/// ```rust
272-
/// use std::rand::{task_rng, Rng};
275+
/// use rand::{task_rng, Rng};
273276
///
274277
/// let choices = [1, 2, 4, 8, 16, 32];
275278
/// let mut rng = task_rng();
@@ -289,7 +292,7 @@ pub trait Rng {
289292
/// # Example
290293
///
291294
/// ```rust
292-
/// use std::rand::{task_rng, Rng};
295+
/// use rand::{task_rng, Rng};
293296
///
294297
/// println!("{:?}", task_rng().shuffle(~[1,2,3]));
295298
/// ```
@@ -304,7 +307,7 @@ pub trait Rng {
304307
/// # Example
305308
///
306309
/// ```rust
307-
/// use std::rand::{task_rng, Rng};
310+
/// use rand::{task_rng, Rng};
308311
///
309312
/// let mut rng = task_rng();
310313
/// let mut y = [1,2,3];
@@ -328,7 +331,7 @@ pub trait Rng {
328331
/// # Example
329332
///
330333
/// ```rust
331-
/// use std::rand::{task_rng, Rng};
334+
/// use rand::{task_rng, Rng};
332335
///
333336
/// let mut rng = task_rng();
334337
/// let sample = rng.sample(range(1, 100), 5);
@@ -359,7 +362,7 @@ pub trait SeedableRng<Seed>: Rng {
359362
/// # Example
360363
///
361364
/// ```rust
362-
/// use std::rand::{Rng, SeedableRng, StdRng};
365+
/// use rand::{Rng, SeedableRng, StdRng};
363366
///
364367
/// let mut rng: StdRng = SeedableRng::from_seed(&[1, 2, 3, 4]);
365368
/// println!("{}", rng.gen::<f64>());
@@ -373,7 +376,7 @@ pub trait SeedableRng<Seed>: Rng {
373376
/// # Example
374377
///
375378
/// ```rust
376-
/// use std::rand::{Rng, SeedableRng, StdRng};
379+
/// use rand::{Rng, SeedableRng, StdRng};
377380
///
378381
/// let mut rng: StdRng = SeedableRng::from_seed(&[1, 2, 3, 4]);
379382
/// println!("{}", rng.gen::<f64>());
@@ -609,7 +612,7 @@ impl Rng for TaskRng {
609612
/// # Example
610613
///
611614
/// ```rust
612-
/// use std::rand::random;
615+
/// use rand::random;
613616
///
614617
/// if random() {
615618
/// let x = random();
@@ -631,8 +634,8 @@ pub fn random<T: Rand>() -> T {
631634
/// `[0,1)`.
632635
///
633636
/// # Example
634-
/// ```rust,ignore
635-
/// use std::rand::{random, Open01};
637+
/// ```rust
638+
/// use rand::{random, Open01};
636639
///
637640
/// let Open01(val) = random::<Open01<f32>>();
638641
/// println!("f32 from (0,1): {}", val);
@@ -647,8 +650,8 @@ pub struct Open01<F>(F);
647650
/// `[0,1)`.
648651
///
649652
/// # Example
650-
/// ```rust,ignore
651-
/// use std::rand::{random, Closed01};
653+
/// ```rust
654+
/// use rand::{random, Closed01};
652655
///
653656
/// let Closed01(val) = random::<Closed01<f32>>();
654657
/// println!("f32 from [0,1]: {}", val);
@@ -657,9 +660,8 @@ pub struct Closed01<F>(F);
657660

658661
#[cfg(test)]
659662
mod test {
660-
use prelude::*;
661-
use vec;
662-
use super::*;
663+
use std::vec;
664+
use super::{Rng, task_rng, random, OSRng, SeedableRng, StdRng};
663665

664666
struct ConstRng { i: u64 }
665667
impl Rng for ConstRng {
@@ -691,7 +693,7 @@ mod test {
691693

692694
#[test]
693695
fn test_gen_range() {
694-
let mut r = rng();
696+
let mut r = task_rng();
695697
for _ in range(0, 1000) {
696698
let a = r.gen_range(-3i, 42);
697699
assert!(a >= -3 && a < 42);
@@ -711,35 +713,35 @@ mod test {
711713
#[test]
712714
#[should_fail]
713715
fn test_gen_range_fail_int() {
714-
let mut r = rng();
716+
let mut r = task_rng();
715717
r.gen_range(5i, -2);
716718
}
717719

718720
#[test]
719721
#[should_fail]
720722
fn test_gen_range_fail_uint() {
721-
let mut r = rng();
723+
let mut r = task_rng();
722724
r.gen_range(5u, 2u);
723725
}
724726

725727
#[test]
726728
fn test_gen_f64() {
727-
let mut r = rng();
729+
let mut r = task_rng();
728730
let a = r.gen::<f64>();
729731
let b = r.gen::<f64>();
730732
debug!("{:?}", (a, b));
731733
}
732734

733735
#[test]
734736
fn test_gen_weighted_bool() {
735-
let mut r = rng();
737+
let mut r = task_rng();
736738
assert_eq!(r.gen_weighted_bool(0u), true);
737739
assert_eq!(r.gen_weighted_bool(1u), true);
738740
}
739741

740742
#[test]
741743
fn test_gen_ascii_str() {
742-
let mut r = rng();
744+
let mut r = task_rng();
743745
debug!("{}", r.gen_ascii_str(10u));
744746
debug!("{}", r.gen_ascii_str(10u));
745747
debug!("{}", r.gen_ascii_str(10u));
@@ -750,21 +752,21 @@ mod test {
750752

751753
#[test]
752754
fn test_gen_vec() {
753-
let mut r = rng();
755+
let mut r = task_rng();
754756
assert_eq!(r.gen_vec::<u8>(0u).len(), 0u);
755757
assert_eq!(r.gen_vec::<u8>(10u).len(), 10u);
756758
assert_eq!(r.gen_vec::<f64>(16u).len(), 16u);
757759
}
758760

759761
#[test]
760762
fn test_choose() {
761-
let mut r = rng();
763+
let mut r = task_rng();
762764
assert_eq!(r.choose([1, 1, 1]), 1);
763765
}
764766

765767
#[test]
766768
fn test_choose_option() {
767-
let mut r = rng();
769+
let mut r = task_rng();
768770
let v: &[int] = &[];
769771
assert!(r.choose_option(v).is_none());
770772

@@ -775,7 +777,7 @@ mod test {
775777

776778
#[test]
777779
fn test_shuffle() {
778-
let mut r = rng();
780+
let mut r = task_rng();
779781
let empty: ~[int] = ~[];
780782
assert_eq!(r.shuffle(~[]), empty);
781783
assert_eq!(r.shuffle(~[1, 1, 1]), ~[1, 1, 1]);
@@ -806,7 +808,7 @@ mod test {
806808
let min_val = 1;
807809
let max_val = 100;
808810

809-
let mut r = rng();
811+
let mut r = task_rng();
810812
let vals = range(min_val, max_val).to_owned_vec();
811813
let small_sample = r.sample(vals.iter(), 5);
812814
let large_sample = r.sample(vals.iter(), vals.len() + 5);
@@ -847,9 +849,8 @@ static RAND_BENCH_N: u64 = 100;
847849
mod bench {
848850
extern crate test;
849851
use self::test::BenchHarness;
850-
use prelude::*;
851-
use rand::{XorShiftRng, StdRng, IsaacRng, Isaac64Rng, Rng, RAND_BENCH_N};
852-
use mem::size_of;
852+
use {XorShiftRng, StdRng, IsaacRng, Isaac64Rng, Rng, RAND_BENCH_N};
853+
use std::mem::size_of;
853854

854855
#[bench]
855856
fn rand_xorshift(bh: &mut BenchHarness) {

‎src/libstd/rand/os.rs renamed to ‎src/librand/os.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111
//! Interfaces to the operating system provided random number
1212
//! generators.
1313
14-
use rand::Rng;
15-
use ops::Drop;
14+
use Rng;
1615

1716
#[cfg(unix)]
18-
use rand::reader::ReaderRng;
17+
use reader::ReaderRng;
1918
#[cfg(unix)]
20-
use io::File;
19+
use std::io::File;
2120

2221
#[cfg(windows)]
23-
use cast;
22+
use std::cast;
2423
#[cfg(windows)]
25-
use libc::{c_long, DWORD, BYTE};
24+
use std::libc::{c_long, DWORD, BYTE};
2625
#[cfg(windows)]
2726
type HCRYPTPROV = c_long;
2827
// the extern functions imported from the runtime on Windows are
@@ -60,7 +59,6 @@ impl OSRng {
6059
/// Create a new `OSRng`.
6160
#[cfg(unix)]
6261
pub fn new() -> OSRng {
63-
use path::Path;
6462
let reader = File::open(&Path::new("/dev/urandom"));
6563
let reader = reader.ok().expect("Error opening /dev/urandom");
6664
let reader_rng = ReaderRng::new(reader);
@@ -106,9 +104,6 @@ impl Rng for OSRng {
106104
unsafe { cast::transmute(v) }
107105
}
108106
fn fill_bytes(&mut self, v: &mut [u8]) {
109-
use container::Container;
110-
use vec::MutableVector;
111-
112107
extern {
113108
fn rust_win32_rand_gen(hProv: HCRYPTPROV, dwLen: DWORD,
114109
pbBuffer: *mut BYTE);
@@ -136,10 +131,9 @@ impl Drop for OSRng {
136131

137132
#[cfg(test)]
138133
mod test {
139-
use prelude::*;
140-
use super::*;
141-
use rand::Rng;
142-
use task;
134+
use super::OSRng;
135+
use Rng;
136+
use std::task;
143137

144138
#[test]
145139
fn test_os_rng() {

‎src/libstd/rand/rand_impls.rs renamed to ‎src/librand/rand_impls.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
//! The implementations of `Rand` for the built-in types.
1212
13-
use char;
14-
use int;
15-
use option::{Option, Some, None};
16-
use rand::{Rand,Rng};
17-
use uint;
13+
use std::char;
14+
use std::int;
15+
use std::uint;
16+
17+
use {Rand,Rng};
1818

1919
impl Rand for int {
2020
#[inline]
@@ -97,7 +97,7 @@ impl Rand for u64 {
9797
macro_rules! float_impls {
9898
($mod_name:ident, $ty:ty, $mantissa_bits:expr, $method_name:ident, $ignored_bits:expr) => {
9999
mod $mod_name {
100-
use rand::{Rand, Rng, Open01, Closed01};
100+
use {Rand, Rng, Open01, Closed01};
101101

102102
static SCALE: $ty = (1u64 << $mantissa_bits) as $ty;
103103

@@ -226,8 +226,7 @@ impl<T: Rand + 'static> Rand for @T {
226226

227227
#[cfg(test)]
228228
mod tests {
229-
use prelude::*;
230-
use rand::{Rng, task_rng, Open01, Closed01};
229+
use {Rng, task_rng, Open01, Closed01};
231230

232231
struct ConstantRng(u64);
233232
impl Rng for ConstantRng {

‎src/libstd/rand/reader.rs renamed to ‎src/librand/reader.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010

1111
//! A wrapper around any Reader to treat it as an RNG.
1212
13-
use container::Container;
14-
use result::{Ok, Err};
15-
use io::Reader;
16-
17-
use rand::Rng;
13+
use Rng;
1814

1915
/// An RNG that reads random bytes straight from a `Reader`. This will
2016
/// work best with an infinite reader, but this is not required.
@@ -24,7 +20,7 @@ use rand::Rng;
2420
/// # Example
2521
///
2622
/// ```rust
27-
/// use std::rand::{reader, Rng};
23+
/// use rand::{reader, Rng};
2824
/// use std::io::MemReader;
2925
///
3026
/// 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> {
7571

7672
#[cfg(test)]
7773
mod test {
78-
use super::*;
79-
use io::MemReader;
80-
use cast;
81-
use rand::*;
82-
use prelude::*;
74+
use super::ReaderRng;
75+
use std::io::MemReader;
76+
use std::cast;
77+
use Rng;
8378

8479
#[test]
8580
fn test_reader_rng_u64() {

‎src/libstd/rand/reseeding.rs renamed to ‎src/librand/reseeding.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
//! A wrapper around another RNG that reseeds it after it
1212
//! generates a certain number of random bytes.
1313
14-
use container::Container;
15-
use default::Default;
16-
use rand::{Rng, SeedableRng};
14+
use std::default::Default;
15+
use {Rng, SeedableRng};
1716

1817
/// How many bytes of entropy the underling RNG is allowed to generate
1918
/// before it is reseeded.
@@ -101,9 +100,8 @@ impl<S, R: SeedableRng<S>, Rsdr: Reseeder<R>>
101100
/// # Example
102101
///
103102
/// ```rust
104-
/// use std::rand;
105-
/// use std::rand::{Rng, SeedableRng};
106-
/// use std::rand::reseeding::{Reseeder, ReseedingRng};
103+
/// use rand::{Rng, SeedableRng};
104+
/// use rand::reseeding::{Reseeder, ReseedingRng};
107105
///
108106
/// struct TickTockReseeder { tick: bool }
109107
/// impl Reseeder<rand::StdRng> for TickTockReseeder {
@@ -142,10 +140,9 @@ impl Default for ReseedWithDefault {
142140

143141
#[cfg(test)]
144142
mod test {
145-
use prelude::*;
146-
use super::*;
147-
use default::Default;
148-
use rand::{SeedableRng, Rng};
143+
use super::{ReseedingRng, ReseedWithDefault};
144+
use std::default::Default;
145+
use {SeedableRng, Rng};
149146

150147
struct Counter {
151148
i: u32
@@ -205,7 +202,7 @@ mod test {
205202
static fill_bytes_v_len: uint = 13579;
206203
#[test]
207204
fn test_rng_fill_bytes() {
208-
use rand::task_rng;
205+
use task_rng;
209206
let mut v = ~[0u8, .. fill_bytes_v_len];
210207
task_rng().fill_bytes(v);
211208

‎src/libstd/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
#[cfg(test)] extern crate native;
7474
#[cfg(test)] extern crate green;
7575

76-
// Make extra accessible for benchmarking
76+
// Make extra and rand accessible for benchmarking/testcases
77+
#[cfg(test)] extern crate rand;
7778
#[cfg(test)] extern crate extra = "extra";
7879

7980
// Make std testable by not duplicating lang items. See #2912
@@ -173,7 +174,6 @@ pub mod c_str;
173174
pub mod os;
174175
pub mod io;
175176
pub mod path;
176-
pub mod rand;
177177
pub mod cast;
178178
pub mod fmt;
179179
pub mod cleanup;

‎src/libsyntax/ext/deriving/rand.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt,
2626
let trait_def = TraitDef {
2727
span: span,
2828
attributes: Vec::new(),
29-
path: Path::new(vec!("std", "rand", "Rand")),
29+
path: Path::new(vec!("rand", "Rand")),
3030
additional_bounds: Vec::new(),
3131
generics: LifetimeBounds::empty(),
3232
methods: vec!(
@@ -35,7 +35,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt,
3535
generics: LifetimeBounds {
3636
lifetimes: Vec::new(),
3737
bounds: vec!(("R",
38-
vec!( Path::new(vec!("std", "rand", "Rng")) )))
38+
vec!( Path::new(vec!("rand", "Rng")) )))
3939
},
4040
explicit_self: None,
4141
args: vec!(
@@ -58,7 +58,6 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
5858
_ => cx.bug("Incorrect number of arguments to `rand` in `deriving(Rand)`")
5959
};
6060
let rand_ident = vec!(
61-
cx.ident_of("std"),
6261
cx.ident_of("rand"),
6362
cx.ident_of("Rand"),
6463
cx.ident_of("rand")
@@ -89,7 +88,7 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
8988
Vec::new());
9089
let rand_name = cx.expr_path(rand_name);
9190

92-
// ::std::rand::Rand::rand(rng)
91+
// ::rand::Rand::rand(rng)
9392
let rv_call = cx.expr_call(trait_span,
9493
rand_name,
9594
vec!( *rng.get(0) ));

‎src/rt/rust_builtin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ rust_win32_rand_acquire(HCRYPTPROV* phProv) {
410410
win32_require
411411
(_T("CryptAcquireContext"),
412412
// changes to the parameters here should be reflected in the docs of
413-
// std::rand::os::OSRng
413+
// rand::os::OSRng
414414
CryptAcquireContext(phProv, NULL, NULL, PROV_RSA_FULL,
415415
CRYPT_VERIFYCONTEXT|CRYPT_SILENT));
416416

‎src/test/compile-fail/task-rng-isnt-sendable.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
// ensure that the TaskRng isn't/doesn't become accidentally sendable.
1212

13+
extern crate rand;
14+
1315
fn test_send<S: Send>() {}
1416

1517
pub fn main() {
16-
test_send::<::std::rand::TaskRng>();
17-
//~^ ERROR: incompatible type `std::rand::TaskRng`, which does not fulfill `Send`
18+
test_send::<::rand::TaskRng>();
19+
//~^ ERROR: incompatible type `rand::TaskRng`, which does not fulfill `Send`
1820
}

0 commit comments

Comments
 (0)
Please sign in to comment.