File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed
branches/try2/src/libstd/rand Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
5
5
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
- refs/heads/try2: 98869799eb2604ecd7c947db117794df10890a2c
8
+ refs/heads/try2: 9db32a2f1d2cfafc519941475f5e660a9ae076f0
9
9
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
10
10
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
11
11
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ use char;
14
14
use int;
15
15
use option:: { Option , Some , None } ;
16
16
use rand:: { Rand , Rng } ;
17
- use u32;
18
17
use uint;
19
18
20
19
impl Rand for int {
@@ -96,21 +95,23 @@ impl Rand for u64 {
96
95
}
97
96
98
97
impl Rand for f32 {
98
+ /// A random `f32` in the range `[0, 1)`.
99
99
#[ inline]
100
100
fn rand < R : Rng > ( rng : & mut R ) -> f32 {
101
- rng. gen :: < f64 > ( ) as f32
101
+ // weird, but this is the easiest way to get 2**32
102
+ static SCALE : f32 = 2.0 * ( 1u32 << 31 ) as f32 ;
103
+ rng. next_u32 ( ) as f32 / SCALE
102
104
}
103
105
}
104
106
105
- static SCALE : f64 = ( u32:: max_value as f64 ) + 1.0f64 ;
106
107
impl Rand for f64 {
108
+ /// A random `f64` in the range `[0, 1)`.
107
109
#[ inline]
108
110
fn rand < R : Rng > ( rng : & mut R ) -> f64 {
109
- let u1 = rng. next_u32 ( ) as f64 ;
110
- let u2 = rng. next_u32 ( ) as f64 ;
111
- let u3 = rng. next_u32 ( ) as f64 ;
111
+ // weird, but this is the easiest way to get 2**64
112
+ static SCALE : f64 = 2.0 * ( 1u64 << 63 ) as f64 ;
112
113
113
- ( ( u1 / SCALE + u2 ) / SCALE + u3 ) / SCALE
114
+ rng . next_u64 ( ) as f64 / SCALE
114
115
}
115
116
}
116
117
You can’t perform that action at this time.
0 commit comments