Skip to content

Incremental std::rand improvements #9362

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 3 commits into from
Sep 22, 2013
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
1 change: 0 additions & 1 deletion mk/rt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ RUNTIME_CXXS_$(1)_$(2) := \
rt/rust_rng.cpp \
rt/rust_upcall.cpp \
rt/rust_uv.cpp \
rt/isaac/randport.cpp \
rt/miniz.cpp \
rt/memory_region.cpp \
rt/boxed_region.cpp \
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,11 @@ mod test {

#[test]
fn test_base64_random() {
use std::rand::{task_rng, random, RngUtil};
use std::rand::{task_rng, random, Rng};
use std::vec;

do 1000.times {
let times = task_rng().gen_uint_range(1, 100);
let times = task_rng().gen_integer_range(1u, 100);
let v = vec::from_fn(times, |_| random::<u8>());
assert_eq!(v.to_base64(STANDARD).from_base64().unwrap(), v);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub trait Deque<T> : Mutable {
mod bench {
use std::container::MutableMap;
use std::{vec, rand};
use std::rand::RngUtil;
use std::rand::Rng;
use test::BenchHarness;

pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint,
Expand Down
5 changes: 2 additions & 3 deletions src/libextra/crypto/cryptoutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ impl <T: FixedBuffer> StandardPadding for T {

#[cfg(test)]
mod test {
use std::rand::IsaacRng;
use std::rand::RngUtil;
use std::rand::{IsaacRng, Rng};
use std::vec;

use cryptoutil::{add_bytes_to_bits, add_bytes_to_bits_tuple};
Expand All @@ -365,7 +364,7 @@ mod test {
digest.reset();

while count < total_size {
let next: uint = rng.gen_uint_range(0, 2 * blocksize + 1);
let next: uint = rng.gen_integer_range(0, 2 * blocksize + 1);
let remaining = total_size - count;
let size = if next > remaining { remaining } else { next };
digest.input(buffer.slice_to(size));
Expand Down
6 changes: 3 additions & 3 deletions src/libextra/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ pub fn inflate_bytes_zlib(bytes: &[u8]) -> ~[u8] {
mod tests {
use super::*;
use std::rand;
use std::rand::RngUtil;
use std::rand::Rng;

#[test]
fn test_flate_round_trip() {
let mut r = rand::rng();
let mut words = ~[];
do 20.times {
let range = r.gen_uint_range(1, 10);
words.push(r.gen_bytes(range));
let range = r.gen_integer_range(1u, 10);
words.push(r.gen_vec::<u8>(range));
}
do 20.times {
let mut input = ~[];
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/num/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
use std::int;
use std::num;
use std::num::{IntConvertible, Zero, One, ToStrRadix, FromStrRadix, Orderable};
use std::rand::{Rng, RngUtil};
use std::rand::Rng;
use std::str;
use std::uint;
use std::vec;
Expand Down
16 changes: 8 additions & 8 deletions src/libextra/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ mod tests {
mod test_tim_sort {

use sort::tim_sort;
use std::rand::RngUtil;
use std::rand::Rng;
use std::rand;
use std::vec;

Expand Down Expand Up @@ -1008,7 +1008,7 @@ mod big_tests {

use sort::*;

use std::rand::RngUtil;
use std::rand::Rng;
use std::rand;
use std::vec;

Expand Down Expand Up @@ -1069,8 +1069,8 @@ mod big_tests {
isSorted(arr);

do 3.times {
let i1 = rng.gen_uint_range(0, n);
let i2 = rng.gen_uint_range(0, n);
let i1 = rng.gen_integer_range(0u, n);
let i2 = rng.gen_integer_range(0u, n);
arr.swap(i1, i2);
}
tim_sort(arr); // 3sort
Expand All @@ -1088,7 +1088,7 @@ mod big_tests {
isSorted(arr);

do (n/100).times {
let idx = rng.gen_uint_range(0, n);
let idx = rng.gen_integer_range(0u, n);
arr[idx] = rng.gen();
}
tim_sort(arr);
Expand Down Expand Up @@ -1141,8 +1141,8 @@ mod big_tests {
isSorted(arr);

do 3.times {
let i1 = rng.gen_uint_range(0, n);
let i2 = rng.gen_uint_range(0, n);
let i1 = rng.gen_integer_range(0u, n);
let i2 = rng.gen_integer_range(0u, n);
arr.swap(i1, i2);
}
tim_sort(arr); // 3sort
Expand All @@ -1160,7 +1160,7 @@ mod big_tests {
isSorted(arr);

do (n/100).times {
let idx = rng.gen_uint_range(0, n);
let idx = rng.gen_integer_range(0u, n);
arr[idx] = @rng.gen();
}
tim_sort(arr);
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/tempfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@


use std::os;
use std::rand::RngUtil;
use std::rand::Rng;
use std::rand;

/// Attempts to make a temporary directory inside of `tmpdir` whose name will
/// have the suffix `suffix`. If no directory can be created, None is returned.
pub fn mkdtemp(tmpdir: &Path, suffix: &str) -> Option<Path> {
let mut r = rand::rng();
for _ in range(0u, 1000) {
let p = tmpdir.push(r.gen_str(16) + suffix);
let p = tmpdir.push(r.gen_ascii_str(16) + suffix);
if os::make_dir(&p, 0x1c0) { // 700
return Some(p);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ mod test_treemap {

use super::*;

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

#[test]
Expand Down Expand Up @@ -1028,7 +1028,7 @@ mod test_treemap {
}

do 30.times {
let r = rng.gen_uint_range(0, ctrl.len());
let r = rng.gen_integer_range(0, ctrl.len());
let (key, _) = ctrl.remove(r);
assert!(map.remove(&key));
check_structure(&map);
Expand Down
6 changes: 3 additions & 3 deletions src/libextra/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use std::char::Char;
use std::container::Container;
use std::to_str::ToStr;
use std::rand;
use std::rand::RngUtil;
use std::rand::Rng;
use std::cmp::Eq;
use std::cast::{transmute,transmute_copy};

Expand Down Expand Up @@ -170,7 +170,7 @@ impl Uuid {
/// of random numbers. Use the rand::Rand trait to supply
/// a custom generator if required.
pub fn new_v4() -> Uuid {
let ub = rand::task_rng().gen_bytes(16);
let ub = rand::task_rng().gen_vec(16);
let mut uuid = Uuid{ bytes: [0, .. 16] };
vec::bytes::copy_memory(uuid.bytes, ub, 16);
uuid.set_variant(VariantRFC4122);
Expand Down Expand Up @@ -488,7 +488,7 @@ impl TotalEq for Uuid {
impl rand::Rand for Uuid {
#[inline]
fn rand<R: rand::Rng>(rng: &mut R) -> Uuid {
let ub = rng.gen_bytes(16);
let ub = rng.gen_vec(16);
let mut uuid = Uuid{ bytes: [0, .. 16] };
vec::bytes::copy_memory(uuid.bytes, ub, 16);
uuid.set_variant(VariantRFC4122);
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use iter::{Iterator, FromIterator, Extendable};
use iter::{FilterMap, Chain, Repeat, Zip};
use num;
use option::{None, Option, Some};
use rand::RngUtil;
use rand::Rng;
use rand;
use uint;
use util::replace;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/num/strconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ mod test {
#[cfg(test)]
mod bench {
use extra::test::BenchHarness;
use rand::{XorShiftRng,RngUtil};
use rand::{XorShiftRng, Rng};
use float;
use to_str::ToStr;

Expand Down
4 changes: 2 additions & 2 deletions src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ mod tests {
use os::{remove_file, setenv, unsetenv};
use os;
use path::Path;
use rand::RngUtil;
use rand::Rng;
use rand;
use run;
use str::StrSlice;
Expand All @@ -1738,7 +1738,7 @@ mod tests {

fn make_rand_name() -> ~str {
let mut rng = rand::rng();
let n = ~"TEST" + rng.gen_str(10u);
let n = ~"TEST" + rng.gen_ascii_str(10u);
assert!(getenv(n).is_none());
n
}
Expand Down
Loading