File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
branches/incoming/src/libcore Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ refs/heads/try: bf67eb2362b7d0f37012f2d6dac604c3bbacd2c6
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
8
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9
- refs/heads/incoming: 8942099614dba3a52e3fc0805ed6c0c37cb371a4
9
+ refs/heads/incoming: 535244cde4640986f29978c5f9c35fd3b40f58db
10
10
refs/heads/dist-snap: 00dbbd01c2aee72982b3e0f9511ae1d4428c3ba9
11
11
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
12
12
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change @@ -55,6 +55,12 @@ impl Rand for i64 {
55
55
}
56
56
}
57
57
58
+ impl Rand for uint {
59
+ fn rand ( rng : @rand:: Rng ) -> uint {
60
+ rng. gen_uint ( )
61
+ }
62
+ }
63
+
58
64
impl Rand for u8 {
59
65
fn rand ( rng : @rand:: Rng ) -> u8 {
60
66
rng. gen_u8 ( )
@@ -149,6 +155,7 @@ pub struct Weighted<T> {
149
155
}
150
156
151
157
pub trait RngUtil {
158
+ /// Return a random value for a Rand type
152
159
fn gen < T : Rand > ( & self ) -> T ;
153
160
/**
154
161
* Return a random int
@@ -739,10 +746,11 @@ pub fn task_rng() -> @Rng {
739
746
}
740
747
741
748
/**
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.
743
751
*/
744
- pub fn random ( ) -> uint {
745
- task_rng ( ) . gen_uint ( )
752
+ pub fn random < T : Rand > ( ) -> T {
753
+ task_rng ( ) . gen ( )
746
754
}
747
755
748
756
@@ -915,8 +923,10 @@ mod tests {
915
923
916
924
#[ test]
917
925
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
919
927
let _n : uint = rand:: random ( ) ;
928
+ let _f : f32 = rand:: random ( ) ;
929
+ let _o : Option < Option < i8 > > = rand:: random ( ) ;
920
930
}
921
931
}
922
932
You can’t perform that action at this time.
0 commit comments