We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eba88ef commit a85e035Copy full SHA for a85e035
src/lib/rand.rs
@@ -14,13 +14,21 @@ native "rust" mod rustrt {
14
type rng =
15
obj {
16
fn next() -> u32;
17
+ fn next_float() -> float;
18
};
19
20
resource rand_res(c: rustrt::rctx) { rustrt::rand_free(c); }
21
22
fn mk_rng() -> rng {
23
obj rt_rng(c: @rand_res) {
24
fn next() -> u32 { ret rustrt::rand_next(**c); }
25
+ fn next_float() -> float {
26
+ let u1 = rustrt::rand_next(**c) as float;
27
+ let u2 = rustrt::rand_next(**c) as float;
28
+ let u3 = rustrt::rand_next(**c) as float;
29
+ let scale = u32::max_value() as float;
30
+ ret ((u1 / scale + u2) / scale + u3) / scale;
31
+ }
32
}
33
ret rt_rng(@rand_res(rustrt::rand_new()));
34
0 commit comments