Skip to content

Instantly share code, notes, and snippets.

@jld
Created July 17, 2012 04:59
Show Gist options
  • Save jld/3127268 to your computer and use it in GitHub Desktop.
Save jld/3127268 to your computer and use it in GitHub Desktop.
Wait for rand::gen_f64 to generate a number greater than 1.0
import rand::rng;
fn main() {
let mut count : u64 = 0;
let rng = rand::seeded_rng(~[17]);
loop {
let r = rng.gen_f64();
if r > 1.0f64 {
io::println(#fmt("%s > 1.0 (after %? tries)",
float::to_str_exact(r as float, 16), count));
break;
}
count += 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment