Skip to content

Commit 5442a47

Browse files
committed
std::rand: remove seed_task_rng and RUST_SEED.
1 parent 62feded commit 5442a47

File tree

1 file changed

+9
-76
lines changed

1 file changed

+9
-76
lines changed

src/libstd/rand/mod.rs

Lines changed: 9 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ from an operating-system source of randomness, e.g. `/dev/urandom` on
2828
Unix systems, and will automatically reseed itself from this source
2929
after generating 32 KiB of random data.
3030
31-
It can be explicitly seeded on a per-task basis with `seed_task_rng`;
32-
this only affects the task-local generator in the task in which it is
33-
called. It can be seeded globally using the `RUST_SEED` environment
34-
variable, which should be an integer. Setting `RUST_SEED` will seed
35-
every task-local RNG with the same seed. Using either of these will
36-
disable the automatic reseeding.
37-
3831
# Examples
3932
4033
```rust
@@ -67,7 +60,6 @@ use prelude::*;
6760
use str;
6861
use u64;
6962
use vec;
70-
use os::getenv;
7163

7264
pub use self::isaac::{IsaacRng, Isaac64Rng};
7365
pub use self::os::OSRng;
@@ -673,25 +665,11 @@ impl XorShiftRng {
673665
}
674666

675667
/// Controls how the task-local RNG is reseeded.
676-
enum TaskRngReseeder {
677-
/// Reseed using the StdRng::new() function, i.e. reading new
678-
/// randomness.
679-
WithNew,
680-
/// Don't reseed at all, e.g. when it has been explicitly seeded
681-
/// by the user.
682-
DontReseed
683-
}
684-
685-
impl Default for TaskRngReseeder {
686-
fn default() -> TaskRngReseeder { WithNew }
687-
}
668+
struct TaskRngReseeder;
688669

689670
impl reseeding::Reseeder<StdRng> for TaskRngReseeder {
690671
fn reseed(&mut self, rng: &mut StdRng) {
691-
match *self {
692-
WithNew => *rng = StdRng::new(),
693-
DontReseed => {}
694-
}
672+
*rng = StdRng::new();
695673
}
696674
}
697675
static TASK_RNG_RESEED_THRESHOLD: uint = 32_768;
@@ -706,61 +684,26 @@ local_data_key!(TASK_RNG_KEY: @mut TaskRng)
706684
/// chaining style, e.g. `task_rng().gen::<int>()`.
707685
///
708686
/// The RNG provided will reseed itself from the operating system
709-
/// after generating a certain amount of randomness, unless it was
710-
/// explicitly seeded either by `seed_task_rng` or by setting the
711-
/// `RUST_SEED` environmental variable to some integer.
687+
/// after generating a certain amount of randomness.
712688
///
713-
/// The internal RNG used is platform and architecture dependent, so
714-
/// may yield differing sequences on different computers, even when
715-
/// explicitly seeded with `seed_task_rng`. If absolute consistency is
716-
/// required, explicitly select an RNG, e.g. `IsaacRng` or
717-
/// `Isaac64Rng`.
689+
/// The internal RNG used is platform and architecture dependent, even
690+
/// if the operating system random number generator is rigged to give
691+
/// the same sequence always. If absolute consistency is required,
692+
/// explicitly select an RNG, e.g. `IsaacRng` or `Isaac64Rng`.
718693
pub fn task_rng() -> @mut TaskRng {
719694
let r = local_data::get(TASK_RNG_KEY, |k| k.map(|&k| *k));
720695
match r {
721696
None => {
722-
// check the environment
723-
let (sub_rng, reseeder) = match getenv("RUST_SEED") {
724-
None => (StdRng::new(), WithNew),
725-
726-
Some(s) => match from_str::<uint>(s) {
727-
None => fail2!("`RUST_SEED` is `{}`, should be a positive integer.", s),
728-
// explicitly seeded, so don't overwrite the seed later.
729-
Some(seed) => (SeedableRng::from_seed(&[seed]), DontReseed),
730-
}
731-
};
732-
733-
let rng = @mut reseeding::ReseedingRng::new(sub_rng,
697+
let rng = @mut reseeding::ReseedingRng::new(StdRng::new(),
734698
TASK_RNG_RESEED_THRESHOLD,
735-
reseeder);
699+
TaskRngReseeder);
736700
local_data::set(TASK_RNG_KEY, rng);
737701
rng
738702
}
739703
Some(rng) => rng
740704
}
741705
}
742706

743-
/// Explicitly seed (or reseed) the task-local random number
744-
/// generator. This stops the RNG from automatically reseeding itself.
745-
///
746-
/// # Example
747-
///
748-
/// ```rust
749-
/// use std::rand;
750-
///
751-
/// fn main() {
752-
/// rand::seed_task_rng(&[10u]);
753-
/// println!("Same every time: {}", rand::random::<uint>());
754-
///
755-
/// rand::seed_task_rng(&[1u, 2, 3, 4, 5, 6, 7, 8]);
756-
/// println!("Same every time: {}", rand::random::<float>());
757-
/// }
758-
/// ```
759-
pub fn seed_task_rng(seed: &[uint]) {
760-
let t_r = task_rng();
761-
(*t_r).reseed((DontReseed, seed));
762-
}
763-
764707
// Allow direct chaining with `task_rng`
765708
impl<R: Rng> Rng for @mut R {
766709
#[inline]
@@ -996,16 +939,6 @@ mod test {
996939
let string2 = r.gen_ascii_str(100);
997940
assert_eq!(string1, string2);
998941
}
999-
1000-
#[test]
1001-
fn test_seed_task_rng() {
1002-
seed_task_rng([1]);
1003-
let first = random::<uint>();
1004-
1005-
seed_task_rng([1]);
1006-
let second = random::<uint>();
1007-
assert_eq!(first, second);
1008-
}
1009942
}
1010943

1011944
#[cfg(test)]

0 commit comments

Comments
 (0)