Struct randomize::PCG32

source ·
pub struct PCG32 {
    pub state: u64,
    pub inc: u64,
}
Expand description

A Permuted Congruential Generator with 32-bit output.

  • Period: 2**64 when inc is odd, otherwise less

Fields§

§state: u64

The generator’s state.

This changes with each step of the generator. It’s the generator’s “position” within the output stream.

§inc: u64

The generator’s increment.

This doesn’t change as the generator advances. Instead it determines which of the possible output streams the generator will use. Each inc value will give a different ordering of all the possible outputs.

Implementations§

source§

impl PCG32

source

pub const fn new(state: u64, inc: u64) -> Self

Creates a new generator by directly using the value given.

source

pub fn next_u32(&mut self) -> u32

Generate the next u32 in the sequence.

source

pub fn jump(&mut self, delta: u64)

Jump the generator the given number of steps forward in the sequence.

This can go x steps forward in only about log2(x) time.

Because the sequence is a loop, you can go “back” by x steps just by passing x.wrapping_neg() to go sufficiently far forward.

Trait Implementations§

source§

impl Clone for PCG32

source§

fn clone(&self) -> PCG32

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PCG32

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Gen32 for PCG32

source§

fn next_u32(&mut self) -> u32

Makes the generator create the next output. Read more
source§

fn next_i32(&mut self) -> i32

Gives a uniformly distributed value.
source§

fn next_bool(&mut self) -> bool

Gives a uniformly distributed value.
source§

fn next_f32_unit(&mut self) -> f32

Gives a value in the range 0.0 ..= 1.0
source§

fn d4(&mut self) -> i32

Gives a value in the range 1 ..= 4
source§

fn d6(&mut self) -> i32

Gives a value in the range 1 ..= 6
source§

fn d8(&mut self) -> i32

Gives a value in the range 1 ..= 8
source§

fn d10(&mut self) -> i32

Gives a value in the range 1 ..= 10
source§

fn d12(&mut self) -> i32

Gives a value in the range 1 ..= 12
source§

fn d20(&mut self) -> i32

Gives a value in the range 1 ..= 20

Auto Trait Implementations§

§

impl RefUnwindSafe for PCG32

§

impl Send for PCG32

§

impl Sync for PCG32

§

impl Unpin for PCG32

§

impl UnwindSafe for PCG32

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.