Skip to content

Commit 783e59f

Browse files
committed
---
yaml --- r: 83800 b: refs/heads/try c: 9db32a2 h: refs/heads/master v: v3
1 parent e7410a1 commit 783e59f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0e4d1fc8cae42e15e00f71d9f439b01bb25a86ae
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
5-
refs/heads/try: 98869799eb2604ecd7c947db117794df10890a2c
5+
refs/heads/try: 9db32a2f1d2cfafc519941475f5e660a9ae076f0
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/rand/rand_impls.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use char;
1414
use int;
1515
use option::{Option, Some, None};
1616
use rand::{Rand,Rng};
17-
use u32;
1817
use uint;
1918

2019
impl Rand for int {
@@ -96,21 +95,23 @@ impl Rand for u64 {
9695
}
9796

9897
impl Rand for f32 {
98+
/// A random `f32` in the range `[0, 1)`.
9999
#[inline]
100100
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
102104
}
103105
}
104106

105-
static SCALE : f64 = (u32::max_value as f64) + 1.0f64;
106107
impl Rand for f64 {
108+
/// A random `f64` in the range `[0, 1)`.
107109
#[inline]
108110
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;
112113

113-
((u1 / SCALE + u2) / SCALE + u3) / SCALE
114+
rng.next_u64() as f64 / SCALE
114115
}
115116
}
116117

0 commit comments

Comments
 (0)