Struct XorShift128Plus

Source
pub struct XorShift128Plus(/* private fields */);
Expand description

§Examples

Construct a RNG from an integer.

extern crate xorshift128plus;

use xorshift128plus::XorShift128Plus;

let mut rng = XorShift128Plus::from_u32(4293262078);

println!("First random float: {}", rng.next());
println!("Second random float: {}", rng.next());

You can also construct a RNG by supplying 16 bytes of raw data. Here we are using the rand crates rand::random to generate 16 bytes of random data to use as the initial seed. This data could also come from a file, a database or anywhere else really.

extern crate rand;
extern crate xorshift128plus;

use xorshift128plus::XorShift128Plus;

let seed: [u8; 16] = rand::random();
let mut rng = XorShift128Plus::from_bytes(seed);

println!("First random float: {}", rng.next());
println!("Second random float: {}", rng.next());

Implementations§

Source§

impl XorShift128Plus

Source

pub fn from_bytes(seed: [u8; 16]) -> XorShift128Plus

Constructs a new RNG with the seed specified as 16 bytes of raw data.

Source

pub fn from_u32(seed: u32) -> XorShift128Plus

Constructs a new RNG with the seed specified as a unsigned 32bit integer. Note that this seeding is suboptimal since it will only contain 32 bits of entropy instead of 128 bits.

Source

pub fn from_u64(seed: u64) -> XorShift128Plus

Constructs a new RNG with the seed specified as a unsigned 64bit integer. Note that this seeding is suboptimal since it will only contain 64 bits of entropy instead of 128 bits.

Source

pub fn next(&mut self) -> f64

Returns the next psuedo-random number between 0 (inclusivly) and 1 (exclusivly).

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.