pub struct RandGenerator { /* private fields */ }
Implementations§
Source§impl RandGenerator
impl RandGenerator
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Examples found in repository?
More examples
examples/basic_with_state.rs (line 5)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
// seed random
let randomness = qrand::RandGenerator::new();
randomness.srand(12345);
// get random number from 0 to u32::MAX
let x = randomness.rand();
// get random number from given range
let x = randomness.gen_range(0., 1.);
assert!(x >= 0. && x < 1.);
println!("x={}", x);
// gen_range works for most of standard number types
let x: u8 = randomness.gen_range(64, 128);
assert!(x >= 64 && x < 128);
println!("x={}", x);
}
Sourcepub fn srand(&self, seed: u64)
pub fn srand(&self, seed: u64)
Examples found in repository?
examples/basic_with_state.rs (line 6)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
// seed random
let randomness = qrand::RandGenerator::new();
randomness.srand(12345);
// get random number from 0 to u32::MAX
let x = randomness.rand();
// get random number from given range
let x = randomness.gen_range(0., 1.);
assert!(x >= 0. && x < 1.);
println!("x={}", x);
// gen_range works for most of standard number types
let x: u8 = randomness.gen_range(64, 128);
assert!(x >= 64 && x < 128);
println!("x={}", x);
}
Sourcepub fn rand(&self) -> u32
pub fn rand(&self) -> u32
Examples found in repository?
examples/basic_with_state.rs (line 9)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
// seed random
let randomness = qrand::RandGenerator::new();
randomness.srand(12345);
// get random number from 0 to u32::MAX
let x = randomness.rand();
// get random number from given range
let x = randomness.gen_range(0., 1.);
assert!(x >= 0. && x < 1.);
println!("x={}", x);
// gen_range works for most of standard number types
let x: u8 = randomness.gen_range(64, 128);
assert!(x >= 64 && x < 128);
println!("x={}", x);
}
Sourcepub fn gen_range<T>(&self, low: T, high: T) -> Twhere
T: RandomRange,
pub fn gen_range<T>(&self, low: T, high: T) -> Twhere
T: RandomRange,
Examples found in repository?
examples/basic_with_state.rs (line 12)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
// seed random
let randomness = qrand::RandGenerator::new();
randomness.srand(12345);
// get random number from 0 to u32::MAX
let x = randomness.rand();
// get random number from given range
let x = randomness.gen_range(0., 1.);
assert!(x >= 0. && x < 1.);
println!("x={}", x);
// gen_range works for most of standard number types
let x: u8 = randomness.gen_range(64, 128);
assert!(x >= 64 && x < 128);
println!("x={}", x);
}
Auto Trait Implementations§
impl !Freeze for RandGenerator
impl RefUnwindSafe for RandGenerator
impl Send for RandGenerator
impl Sync for RandGenerator
impl Unpin for RandGenerator
impl UnwindSafe for RandGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more