quad_rand

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)
4
5
6
7
8
9
10
11
12
13
fn main() {
    let randomness = quad_rand::RandGenerator::new();

    let mut vec = vec![1, 2, 3, 4, 5, 6];
    println!("ordered: {:?}", vec);

    // QuadRand is rand::RngCore implementation, allowing to use all the cool stuff from rand
    vec.shuffle(&mut QuadRandWithState(&randomness));
    println!("shuffled: {:?}", vec);
}
More examples
Hide additional 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);
}
Source

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

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);
}
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)
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§

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