Struct RandGenerator

Source
pub struct RandGenerator { /* private fields */ }

Implementations§

Source§

impl RandGenerator

Source

pub const fn new() -> Self

Examples found in repository?
examples/compat_with_state.rs (line 5)
4fn main() {
5    let randomness = quad_rand::RandGenerator::new();
6
7    let mut vec = vec![1, 2, 3, 4, 5, 6];
8    println!("ordered: {:?}", vec);
9
10    // QuadRand is rand::RngCore implementation, allowing to use all the cool stuff from rand
11    vec.shuffle(&mut QuadRandWithState(&randomness));
12    println!("shuffled: {:?}", vec);
13}
More examples
Hide additional 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}
Source

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}
Source

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}
Source

pub fn gen_range<T>(&self, low: T, high: T) -> T
where 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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V