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)
3fn main() {
4 // seed random
5 let randomness = qrand::RandGenerator::new();
6 randomness.srand(12345);
7
8 // get random number from 0 to u32::MAX
9 let x = randomness.rand();
10
11 // get random number from given range
12 let x = randomness.gen_range(0., 1.);
13 assert!(x >= 0. && x < 1.);
14 println!("x={}", x);
15
16 // gen_range works for most of standard number types
17 let x: u8 = randomness.gen_range(64, 128);
18 assert!(x >= 64 && x < 128);
19 println!("x={}", x);
20}Sourcepub fn srand(&self, seed: u64)
pub fn srand(&self, seed: u64)
Examples found in repository?
examples/basic_with_state.rs (line 6)
3fn main() {
4 // seed random
5 let randomness = qrand::RandGenerator::new();
6 randomness.srand(12345);
7
8 // get random number from 0 to u32::MAX
9 let x = randomness.rand();
10
11 // get random number from given range
12 let x = randomness.gen_range(0., 1.);
13 assert!(x >= 0. && x < 1.);
14 println!("x={}", x);
15
16 // gen_range works for most of standard number types
17 let x: u8 = randomness.gen_range(64, 128);
18 assert!(x >= 64 && x < 128);
19 println!("x={}", x);
20}Sourcepub fn rand(&self) -> u32
pub fn rand(&self) -> u32
Examples found in repository?
examples/basic_with_state.rs (line 9)
3fn main() {
4 // seed random
5 let randomness = qrand::RandGenerator::new();
6 randomness.srand(12345);
7
8 // get random number from 0 to u32::MAX
9 let x = randomness.rand();
10
11 // get random number from given range
12 let x = randomness.gen_range(0., 1.);
13 assert!(x >= 0. && x < 1.);
14 println!("x={}", x);
15
16 // gen_range works for most of standard number types
17 let x: u8 = randomness.gen_range(64, 128);
18 assert!(x >= 64 && x < 128);
19 println!("x={}", x);
20}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)
3fn main() {
4 // seed random
5 let randomness = qrand::RandGenerator::new();
6 randomness.srand(12345);
7
8 // get random number from 0 to u32::MAX
9 let x = randomness.rand();
10
11 // get random number from given range
12 let x = randomness.gen_range(0., 1.);
13 assert!(x >= 0. && x < 1.);
14 println!("x={}", x);
15
16 // gen_range works for most of standard number types
17 let x: u8 = randomness.gen_range(64, 128);
18 assert!(x >= 64 && x < 128);
19 println!("x={}", x);
20}Auto Trait Implementations§
impl !Freeze for RandGenerator
impl RefUnwindSafe for RandGenerator
impl Send for RandGenerator
impl Sync for RandGenerator
impl Unpin for RandGenerator
impl UnsafeUnpin 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