Struct onejoker::utils::Random

source ·
pub struct Random { /* private fields */ }
Expand description

wiki | A simple xoshiro256** PRNG

I know, I know, first rule of PRNG club is don’t roll your own, just use the library. I’m pretty sure my Math chops are up to understanding this stuff well enough to bend that rule a bit, and I just don’t like the standard library for this application. Xoshiro crate is better, but contains a lot of stuff I don’t need.

Implementations§

source§

impl Random

source

pub fn new() -> Self

Create a new randomizer object. Will be lazily initialized and seeded on first use.

source

pub fn seeded(self, seed: u64) -> Self

Seed with given number for reproducibility.

source

pub fn next64(&mut self) -> u64

Execute one round of the xoshiro256** 64-bit PRNG.

source

pub fn jump(&mut self)

Jump is equivalent to 2^128 calls to next(); it can be used to generate non-overlapping subsequences for parallel computations.

source

pub fn next32(&mut self) -> u32

Get 32 random bits.

source

pub fn next16(&mut self) -> u16

Get 16 random bits.

source

pub fn uniform32(&mut self, limit: usize) -> usize

Faster, but not precisely uniform, using Lemire’s method.

source

pub fn uniform16(&mut self, limit: usize) -> usize

Slower, but precisely uniform, using rejection sampling with mask.

Trait Implementations§

source§

impl Clone for Random

source§

fn clone(&self) -> Random

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 Random

source§

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

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

impl Default for Random

source§

fn default() -> Random

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Random

§

impl RefUnwindSafe for Random

§

impl Send for Random

§

impl Sync for Random

§

impl Unpin for Random

§

impl UnwindSafe for Random

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.