Editor's note: This answer is for a version of Rust prior to 1.0 and is not valid in Rust 1.0. See Manoel Stilpen's answer instead.
This has been changing a lot recently (sorry! it's all been me), and in Rust 0.8 it was called gen_integer_range
(note the /0.8/
rather than /master/
in the URL, if you are using 0.8 you need to be reading those docs).
A word of warning: .gen_integer_range
was entirely incorrect in many ways, the new .gen_range
doesn't have incorrectness problems.
Code for master (where .gen_range
works fine):
use std::rand::{task_rng, Rng};
fn main() {
// a number from [-40.0, 13000.0)
let num: f64 = task_rng().gen_range(-40.0, 1.3e4);
println!("{}", num);
}