Struct tiamat::Pcg [−][src]
pub struct Pcg { /* fields omitted */ }
A Permuted Congruential Generator.
Permuted congruential generators (PCGs) are linear congruential generators that, instead of using their state as the random number, permute their state. This improves their statistical quality significantly, while maintaining quite fast performance; they are however not cryptographically secure.
The main interface for this struct are its Rng
and SeedableRng
implementations.
In addition, Pcg
also provides functions for advancing and reversing
itself by an arbitrary amount of steps quickly.
Pcg
provides for 263 different sequences, these are specified
by the second field of the seed (see reseed
's documentation).
It implements the "xsh-rr-64-32" scheme.
For more information on PCGs, see pcgrandom.org.
Methods
impl Pcg
[src]
impl Pcg
pub fn new(seed: u64, sequence: u64) -> Pcg
[src]
pub fn new(seed: u64, sequence: u64) -> Pcg
Creates the Pcg
with a given seed and sequence.
The highest bit of sequence
is ignored.
pub fn advance(&mut self, delta: u64)
[src]
pub fn advance(&mut self, delta: u64)
Advances the Pcg
by delta
steps.
This uses a method similar to fast exponentiation and thus runs in
O(log(delta
)) time.
pub fn revert(&mut self, delta: u64)
[src]
pub fn revert(&mut self, delta: u64)
Reverses the Pcg
by delta
steps.
This is a convenience method, reversing by delta
steps is the same as
advancing by 264-delta
steps.
pub fn steps_since(&self, other: &Pcg) -> Option<u64>
[src]
pub fn steps_since(&self, other: &Pcg) -> Option<u64>
Calculates the distance between Pcg
s of the same sequence.
Errors
If self
and other
are on different streams, this method returns
None
.
Trait Implementations
impl Debug for Pcg
[src]
impl Debug for Pcg
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Clone for Pcg
[src]
impl Clone for Pcg
fn clone(&self) -> Pcg
[src]
fn clone(&self) -> Pcg
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl PartialEq for Pcg
[src]
impl PartialEq for Pcg
fn eq(&self, other: &Pcg) -> bool
[src]
fn eq(&self, other: &Pcg) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Pcg) -> bool
[src]
fn ne(&self, other: &Pcg) -> bool
This method tests for !=
.
impl Eq for Pcg
[src]
impl Eq for Pcg
impl RandomGen for Pcg
[src]
impl RandomGen for Pcg
fn gen_u32(&mut self) -> u32
[src]
fn gen_u32(&mut self) -> u32
Returns a (pseudo-)random, uniformly distributed u32
. Read more
fn gen<R: Random>(&mut self) -> R where
Self: Sized,
[src]
fn gen<R: Random>(&mut self) -> R where
Self: Sized,
Generates a random value. Read more
fn build<B, R>(&mut self, builder: &B) -> R where
B: BuildRandom<R>,
Self: Sized,
[src]
fn build<B, R>(&mut self, builder: &B) -> R where
B: BuildRandom<R>,
Self: Sized,
Generates a random value according to some specification. Read more
fn choose_from<'a, T>(&mut self, xs: &'a [T]) -> &'a T where
Self: Sized,
[src]
fn choose_from<'a, T>(&mut self, xs: &'a [T]) -> &'a T where
Self: Sized,
Chooses a random element from the slice, where each element has the same probability of being chosen. Read more
ⓘImportant traits for IterGen<'a, G, R>fn iter_gen<R: Random>(&mut self) -> IterGen<Self, R> where
Self: Sized,
[src]
fn iter_gen<R: Random>(&mut self) -> IterGen<Self, R> where
Self: Sized,
Returns an iterator over randomly generated values. Read more
ⓘImportant traits for IterBuild<'a, G, B, R>fn iter_build<'a, B: 'a, R>(
&'a mut self,
builder: &'a B
) -> IterBuild<'a, Self, B, R> where
B: BuildRandom<R>,
Self: Sized,
[src]
fn iter_build<'a, B: 'a, R>(
&'a mut self,
builder: &'a B
) -> IterBuild<'a, Self, B, R> where
B: BuildRandom<R>,
Self: Sized,
Returns an iterator over randomly built values. Read more
ⓘImportant traits for IterChooseFrom<'a, G, T>fn iter_choose_from<'a, T>(
&'a mut self,
xs: &'a [T]
) -> IterChooseFrom<'a, Self, T> where
Self: Sized,
[src]
fn iter_choose_from<'a, T>(
&'a mut self,
xs: &'a [T]
) -> IterChooseFrom<'a, Self, T> where
Self: Sized,
Returns an iterator over values randomly chosen from a slice. Read more
fn gen_u64(&mut self) -> u64
[src]
fn gen_u64(&mut self) -> u64
Returns a (pseudo-)random, uniformly distributed u64
. Read more
fn fill_buffer(&mut self, buffer: &mut [u8])
[src]
fn fill_buffer(&mut self, buffer: &mut [u8])
Fills the buffer with (pseudo-)random bytes. Read more
impl Random for Pcg
[src]
impl Random for Pcg