Skip to content

Commit 81a2822

Browse files
committed
---
yaml --- r: 55727 b: refs/heads/master c: 535244c h: refs/heads/master i: 55725: 06c5f84 55723: 44bbd25 55719: 0e4a11b 55711: 05f9437 v: v3
1 parent b603fce commit 81a2822

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 8942099614dba3a52e3fc0805ed6c0c37cb371a4
2+
refs/heads/master: 535244cde4640986f29978c5f9c35fd3b40f58db
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a

trunk/src/libcore/rand.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ impl Rand for i64 {
5555
}
5656
}
5757

58+
impl Rand for uint {
59+
fn rand(rng: @rand::Rng) -> uint {
60+
rng.gen_uint()
61+
}
62+
}
63+
5864
impl Rand for u8 {
5965
fn rand(rng: @rand::Rng) -> u8 {
6066
rng.gen_u8()
@@ -149,6 +155,7 @@ pub struct Weighted<T> {
149155
}
150156

151157
pub trait RngUtil {
158+
/// Return a random value for a Rand type
152159
fn gen<T:Rand>(&self) -> T;
153160
/**
154161
* Return a random int
@@ -739,10 +746,11 @@ pub fn task_rng() -> @Rng {
739746
}
740747

741748
/**
742-
* Returns a random uint, using the task's based random number generator.
749+
* Returns a random value of a Rand type, using the task's random number
750+
* generator.
743751
*/
744-
pub fn random() -> uint {
745-
task_rng().gen_uint()
752+
pub fn random<T: Rand>() -> T {
753+
task_rng().gen()
746754
}
747755

748756

@@ -915,8 +923,10 @@ mod tests {
915923

916924
#[test]
917925
fn random() {
918-
// not sure how to test this aside from just getting a number
926+
// not sure how to test this aside from just getting some values
919927
let _n : uint = rand::random();
928+
let _f : f32 = rand::random();
929+
let _o : Option<Option<i8>> = rand::random();
920930
}
921931
}
922932

0 commit comments

Comments
 (0)