RNG

Struct RNG 

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

RNG is a random number generator.

Implementations§

Source§

impl RNG

Source

pub fn new() -> Self

new is a constructor.

Source

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

with_seed is a constructor with seed.

Source

pub fn i32_f32(&self) -> ((i32, f32), Self)

i32_f32 generates a tuple of i32 and f32.

Source

pub fn f32_i32(&self) -> ((f32, i32), Self)

f32_i32 generates a tuple of f32 and i32.

Source

pub fn f32_3(&self) -> ((f32, f32, f32), Self)

f32_3 generates a tuple of f32, f32 and f32.

Source

pub fn i32s(&self, count: u32) -> (Vec<i32>, Self)

i32s generates a vector of i32 with pre-allocated capacity.

This method automatically selects the most efficient implementation based on the size:

  • For small sizes (< 50,000), it uses a direct StdRng implementation
  • For large sizes (>= 50,000), it uses parallel processing
Source

pub fn i32s_direct(&self, count: u32) -> (Vec<i32>, Self)

i32s_direct generates a vector of i32 using direct StdRng access.

Source

pub fn i32s_parallel(&self, count: u32) -> (Vec<i32>, Self)

i32s_parallel generates a vector of i32 using parallel processing.

Source

pub fn unit<A>(a: A) -> Box<dyn FnMut(RNG) -> (A, RNG)>
where A: Clone + 'static,

unit generates a function that returns a tuple of A and RNG.

Source

pub fn sequence<A, F>(fs: Vec<F>) -> Box<dyn FnMut(RNG) -> (Vec<A>, RNG)>
where A: Clone + 'static, F: FnMut(RNG) -> (A, RNG) + 'static,

sequence generates a function that returns a tuple of Vec<A> and RNG, pre-allocating capacity based on the number of functions.

Source

pub fn int_value() -> Box<dyn FnMut(RNG) -> (i32, RNG)>

int_value generates a function that returns a tuple of i32 and RNG.

Source

pub fn double_value() -> Box<dyn FnMut(RNG) -> (f32, RNG)>

double_value generates a function that returns a tuple of f32 and RNG.

Source

pub fn map<A, B, F1, F2>(s: F1, f: F2) -> Box<dyn FnMut(RNG) -> (B, RNG)>
where F1: FnMut(RNG) -> (A, RNG) + 'static, F2: FnMut(A) -> B + 'static,

map generates a function that returns a tuple of B and RNG.

Source

pub fn map2<F1, F2, F3, A, B, C>( ra: F1, rb: F2, f: F3, ) -> Box<dyn FnMut(RNG) -> (C, RNG)>
where F1: FnMut(RNG) -> (A, RNG) + 'static, F2: FnMut(RNG) -> (B, RNG) + 'static, F3: FnMut(A, B) -> C + 'static,

map2 generates a function that returns a tuple of C and RNG.

Source

pub fn both<F1, F2, A, B>( ra: F1, rb: F2, ) -> Box<dyn FnMut(RNG) -> ((A, B), RNG)>
where F1: FnMut(RNG) -> (A, RNG) + 'static, F2: FnMut(RNG) -> (B, RNG) + 'static,

both generates a function that returns a tuple of (A, B) and RNG.

Source

pub fn rand_int_double() -> Box<dyn FnMut(RNG) -> ((i32, f32), RNG)>

rand_int_double generates a function that returns a tuple of (i32, f32) and RNG.

Source

pub fn rand_double_int() -> Box<dyn FnMut(RNG) -> ((f32, i32), RNG)>

rand_double_int generates a function that returns a tuple of (f32, i32) and RNG.

Source

pub fn flat_map<A, B, F, GF, BF>(f: F, g: GF) -> Box<dyn FnMut(RNG) -> (B, RNG)>
where F: FnMut(RNG) -> (A, RNG) + 'static, BF: FnMut(RNG) -> (B, RNG) + 'static, GF: FnMut(A) -> BF + 'static,

flat_map generates a function that returns a tuple of B and RNG.

Trait Implementations§

Source§

impl Clone for RNG

Source§

fn clone(&self) -> RNG

Returns a duplicate 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 RNG

Source§

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

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

impl Default for RNG

Source§

fn default() -> Self

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

impl NextRandValue for RNG

Source§

fn next_i64(&self) -> (i64, Self)

next_i64 generates an i64 and an updated instance of Self.
Source§

fn next_i32(&self) -> (i32, Self)

next_i32 generates an i32 and an updated instance of Self.
Source§

fn next_i16(&self) -> (i16, Self)

next_i16 generates an i16 and an updated instance of Self.
Source§

fn next_i8(&self) -> (i8, Self)

next_i8 generates an i8 and an updated instance of Self.
Source§

fn next_u64(&self) -> (u64, Self)

next_u64 generates a u64 and an updated instance of Self.
Source§

fn next_u32(&self) -> (u32, Self)

next_u32 generates a u32 and an updated instance of Self.
Source§

fn next_u16(&self) -> (u16, Self)

next_u16 generates a u16 and an updated instance of Self.
Source§

fn next_u8(&self) -> (u8, Self)

next_u8 generates a u8 and an updated instance of Self.
Source§

fn next_f64(&self) -> (f64, Self)

Generates an f64 in the range [0.0, 1.0) and an updated instance of Self. Read more
Source§

fn next_f32(&self) -> (f32, Self)

Generates an f32 in the range [0.0, 1.0) and an updated instance of Self. Read more
Source§

fn next_bool(&self) -> (bool, Self)

next_bool generates a bool and an updated instance of Self.
Source§

impl PartialEq for RNG

Source§

fn eq(&self, other: &RNG) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for RNG

Auto Trait Implementations§

§

impl Freeze for RNG

§

impl !RefUnwindSafe for RNG

§

impl !Send for RNG

§

impl !Sync for RNG

§

impl Unpin for RNG

§

impl !UnwindSafe for RNG

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