Skip to content

Commit a5042d5

Browse files
committed
Merge pull request #3642 from dbp/random
core::rand - adding rand::random(), a shortcut to generate a uint
2 parents 9284179 + 0b9a47a commit a5042d5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libcore/rand.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ pub fn task_rng() -> Rng {
334334
}
335335
}
336336

337+
/**
338+
* Returns a random uint, using the task's based random number generator.
339+
*/
340+
pub fn random() -> uint {
341+
task_rng().gen_uint()
342+
}
343+
337344

338345
#[cfg(test)]
339346
pub mod tests {
@@ -495,6 +502,12 @@ pub mod tests {
495502
assert r.shuffle(~[1, 1, 1]) == ~[1, 1, 1];
496503
assert r.gen_uint_range(0u, 1u) == 0u;
497504
}
505+
506+
#[test]
507+
pub fn random() {
508+
// not sure how to test this aside from just getting a number
509+
let _n : uint = rand::random();
510+
}
498511
}
499512

500513

0 commit comments

Comments
 (0)