From 0b9a47a18969f770f57b84f50a22e48b97d6ea28 Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Tue, 2 Oct 2012 17:15:14 -0400 Subject: [PATCH] core::rand - adding rand::random(), a shortcut to generate a uint with task-local rng --- src/libcore/rand.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index f6b7dfa568c28..32f77a533a67e 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -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(); + } }