core::rand - adding rand::random(), a shortcut to generate a uint with task-local rng

This commit is contained in:
Daniel Patterson 2012-10-02 17:15:14 -04:00
parent 9284179311
commit 0b9a47a189

View File

@ -334,6 +334,13 @@ pub fn task_rng() -> Rng {
}
}
/**
* Returns a random uint, using the task's based random number generator.
*/
pub fn random() -> uint {
task_rng().gen_uint()
}
#[cfg(test)]
pub mod tests {
@ -495,6 +502,12 @@ pub mod tests {
assert r.shuffle(~[1, 1, 1]) == ~[1, 1, 1];
assert r.gen_uint_range(0u, 1u) == 0u;
}
#[test]
pub fn random() {
// not sure how to test this aside from just getting a number
let _n : uint = rand::random();
}
}