[][src]Struct srand::Rand

pub struct Rand<S> where
    S: Source
{ /* fields omitted */ }

Methods

impl<S> Rand<S> where
    S: Source
[src]

pub fn new(src: S) -> Rand<S>[src]

Creates a new Rand that uses random values from src to generate other random values.

Examples

use srand::Rand;
use srand::RngSource;

fn main() -> std::io::Result<()> {
    let mut r: Rand<_> = Rand::new(RngSource::new(1));
    Ok(())
}

pub fn seed(&mut self, seed: i64)[src]

Seed uses the provided seed value to initialize the generator to a deterministic state.

pub fn int64(&mut self) -> i64[src]

Returns a non-negative pseudo-random 63-bit integer as an i64.

Examples

use srand::{Rand,RngSource};

fn main() -> std::io::Result<()> {
    let mut r: Rand<_> = Rand::new(RngSource::new(1));
    println!("n: {}", r.int64());
    Ok(())
}

pub fn uint64(&mut self) -> u64[src]

Returns a pseudo-random 64-bit value as a u64.

Examples

use srand::{Rand, RngSource};

fn main() -> std::io::Result<()> {
    let mut r: Rand<_> = Rand::new(RngSource::new(1));
    println!("n: {}", r.uint64());
    Ok(())
}

pub fn int32(&mut self) -> i32[src]

i32 returns a non-negative pseudo-random 31-bit integer as an i32.

Examples

use srand::{Rand, RngSource};

fn main() -> std::io::Result<()> {
    let mut r: Rand<_> = Rand::new(RngSource::new(1));
    println!("n: {}", r.int32());
    Ok(())
}

pub fn uint32(&mut self) -> u32[src]

Returns a pseudo-random 32-bit value as a u32.

Examples

use srand::{Rand, RngSource};

fn main() -> std::io::Result<()> {
    let mut r: Rand<_> = Rand::new(RngSource::new(1));
    println!("n: {}", r.uint32());
    Ok(())
}

pub fn int32n(&mut self, n: i32) -> i32[src]

Returns an i32, a non-negative pseudo-random number in [0,n). It panics if n <= 0.

Examples

use srand::{Rand, RngSource};

fn main() -> std::io::Result<()> {
    let mut r: Rand<_> = Rand::new(RngSource::new(1));
    println!("n: {}", r.int32n(90000001));
    Ok(())
}

pub fn int64n(&mut self, n: i64) -> i64[src]

Returns an i64, a non-negative pseudo-random number in [0,n). It panics if n <= 0.

Examples

use srand::{Rand, RngSource};

fn main() -> std::io::Result<()> {
    let mut r: Rand<_> = Rand::new(RngSource::new(1));
    println!("n: {}", r.int64n(90000001));
    Ok(())
}

pub fn float32(&mut self) -> f32[src]

Returns a f32, a pseudo-random number in [0.0,1.0).

Examples

use srand::{Rand, RngSource};

fn main() -> std::io::Result<()> {
    let mut r: Rand<_> = Rand::new(RngSource::new(1));
    println!("n: {}", r.float32());
    Ok(())
}

pub fn float64(&mut self) -> f64[src]

Returns a f64, a pseudo-random number in [0.0,1.0).

Examples

use srand::{Rand, RngSource};

fn main() -> std::io::Result<()> {
    let mut r: Rand<_> = Rand::new(RngSource::new(1));
    println!("n: {}", r.float64());
    Ok(())
}

pub fn shuffle<T>(&mut self, array: &mut Vec<T>)[src]

Shuffle pseudo-randomizes the order of elements.

Examples

use srand::{Rand, RngSource};

fn main() -> std::io::Result<()> {
    let mut r: Rand<_> = Rand::new(RngSource::new(1));
    let mut v = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
    println!("result: {:?}", r.shuffle(&mut v));
    println!("shuffled array: {:?}", v);
    Ok(())
}

Trait Implementations

impl<S: Source> Send for Rand<S> where
    S: Send
[src]

impl<S: Source> Sync for Rand<S> where
    S: Sync
[src]

impl<S: Sized + Source> Clone for Rand<S> where
    S: Clone
[src]

Auto Trait Implementations

impl<S> Unpin for Rand<S> where
    S: Unpin

impl<S> UnwindSafe for Rand<S> where
    S: UnwindSafe

impl<S> RefUnwindSafe for Rand<S> where
    S: RefUnwindSafe

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]