Skip to main content

Hrng

Struct Hrng 

Source
pub struct Hrng { /* private fields */ }
Expand description

Hierarchical random number generator.

Produce deterministic random series of numbers with uniform distribution. Handy to be used for paralelism.

Master random number generator produce children and each child might produce more children as much as dataflows in progam.

Implementations§

Source§

impl Hrng

Source

pub fn master() -> Self

Construct master hierarchical random number generator with default seed phrase.

§Example
use deterministic_rand :: { Hrng, Rng };
let hrng = Hrng ::master();
let rng_ref = hrng.rng_ref();
let mut rng = rng_ref.lock().unwrap();
let got: u64 = rng.gen();
Source

pub fn master_with_seed(seed: Seed) -> Self

Construct hierarchical random number generator with help of seed phrase.

§Example
use deterministic_rand :: { Hrng, Rng };
let hrng = Hrng ::master_with_seed( "master1".into() );
let rng_ref = hrng.rng_ref();
let mut rng = rng_ref.lock().unwrap();
let got: u64 = rng.gen();
Source

pub fn rng_ref(&self) -> Arc<Mutex<ChaCha8Rng>>

Get a reference to the current random number generator using a reference counter and mutex.

Returns a shared Arc< Mutex< Generator >>.

§Example
let rng_ref = hrng.rng_ref();
let mut rng = rng_ref.lock().unwrap();
let got: u64 = rng.gen();
Source

pub fn child(&self, index: usize) -> Self

Creates new child hierarchical random number generator by index seed.

Source

pub fn _children_len(&self) -> usize

Returns number of children created by this generator. Used only for diagnostics.

Trait Implementations§

Source§

impl Clone for Hrng

Source§

fn clone(&self) -> Hrng

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Hrng

Source§

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

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

impl Default for Hrng

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Hrng

§

impl RefUnwindSafe for Hrng

§

impl Send for Hrng

§

impl Sync for Hrng

§

impl Unpin for Hrng

§

impl UnsafeUnpin for Hrng

§

impl UnwindSafe for Hrng

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V