Rand

Struct Rand 

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

Implementations§

Source§

impl Rand

Source

pub fn new(seed: u64) -> Self

Creates instance of random number generator.

use simple_rnd::Rand;

let mut rand = Rand::new(0);
println!("{}", rand.next());
Examples found in repository?
examples/simple.rs (line 4)
3fn main() {
4    let mut rand = Rand::new(0); // The parameter is the starting value (seed)
5    for _ in 0..16 {
6        println!("{}", rand.next()); // rand.next() generates next u64 number
7    }
8}
More examples
Hide additional examples
examples/mix.rs (line 4)
3fn main() {
4    let mut rand = Rand::new(0); // The parameter is the starting value (seed)
5    let string = "Some test string";
6    for byte in string.as_bytes() {
7        rand.mix(*byte as u64);
8    }
9    for _ in 0..16 {
10        println!("{}", rand.next()); // rand.next() generates next u64 number
11    }
12}
Source

pub fn next(&mut self) -> u64

Generates the next random u64 number.

use simple_rnd::Rand;

let mut rand = Rand::new(0);
println!("{}", rand.next());
Examples found in repository?
examples/simple.rs (line 6)
3fn main() {
4    let mut rand = Rand::new(0); // The parameter is the starting value (seed)
5    for _ in 0..16 {
6        println!("{}", rand.next()); // rand.next() generates next u64 number
7    }
8}
More examples
Hide additional examples
examples/mix.rs (line 10)
3fn main() {
4    let mut rand = Rand::new(0); // The parameter is the starting value (seed)
5    let string = "Some test string";
6    for byte in string.as_bytes() {
7        rand.mix(*byte as u64);
8    }
9    for _ in 0..16 {
10        println!("{}", rand.next()); // rand.next() generates next u64 number
11    }
12}
Source

pub fn mix(&mut self, other: u64) -> u64

Mixes the seed with some u64 number.

use simple_rnd::Rand;

let mut rand = Rand::new(0);
 
println!("{}", rand.mix(228));
Examples found in repository?
examples/mix.rs (line 7)
3fn main() {
4    let mut rand = Rand::new(0); // The parameter is the starting value (seed)
5    let string = "Some test string";
6    for byte in string.as_bytes() {
7        rand.mix(*byte as u64);
8    }
9    for _ in 0..16 {
10        println!("{}", rand.next()); // rand.next() generates next u64 number
11    }
12}

Auto Trait Implementations§

§

impl Freeze for Rand

§

impl RefUnwindSafe for Rand

§

impl Send for Rand

§

impl Sync for Rand

§

impl Unpin for Rand

§

impl UnwindSafe for Rand

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.