Skip to main content

Rng

Struct Rng 

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

Implements RomuTrio.

Implementations§

Source§

impl Rng

Source

pub fn new() -> Self

Creates a new Rng with a seed from the best available randomness source.

Source

pub const fn from_seed_with_64bit(seed: u64) -> Self

Creates a new Rng from the given 64-bit seed.

Source

pub const fn from_seed_with_192bit(seed: [u64; 3]) -> Self

Creates a new Rng from the given 192-bit seed.

If the seed is of low quality, user should call Rng::mix() to improve the quality of the first couple of random numbers.

§Notice

The variables must be seeded such that at least one bit of state is non-zero.

Source

pub fn seed_source(&self) -> SeedSource

Shows which source was used to acquire the seed.

Source

pub fn seed(&self)

Re-seeds the Rng from the best available randomness source.

Source

pub fn seed_with_64bit(&self, seed: u64)

Re-seeds the Rng with the given 64-bit seed.

Source

pub fn seed_with_192bit(&self, seed: [u64; 3])

Re-seeds the Rng from the given 192-bit seed.

If the seed is of low quality, user should call Rng::mix() to improve the quality of the first couple of random numbers.

§Notice

The variables must be seeded such that at least one bit of state is non-zero.

Source

pub fn mix(&self)

Mixes the state, which should improve the quality of the random numbers.

Should be called when having (re-)seeded the generator with a fixed value of low randomness.

Source

pub fn u8(&self) -> u8

Generates a random u8 value.

Source

pub fn u16(&self) -> u16

Generates a random u16 value.

Source

pub fn u32(&self) -> u32

Generates a random u32 value.

Source

pub fn u64(&self) -> u64

Generates a random u64 value.

Source

pub fn usize(&self) -> usize

Generates a random usize value.

Source

pub fn i8(&self) -> i8

Generates a random i8 value.

Source

pub fn i16(&self) -> i16

Generates a random i16 value.

Source

pub fn i32(&self) -> i32

Generates a random i32 value.

Source

pub fn i64(&self) -> i64

Generates a random i64 value.

Source

pub fn isize(&self) -> isize

Generates a random isize value.

Source

pub fn bool(&self) -> bool

Generates a random bool value.

Source

pub fn f32(&self) -> f32

Generates a random f32 value in range (0..1).

Source

pub fn f64(&self) -> f64

Generates a random f64 value in range (0..1).

Source

pub fn shuffle<T>(&self, slice: &mut [T])

Randomly shuffles a slice.

Source

pub fn fill_bytes(&self, slice: &mut [u8])

Fills a mutable [u8] slice with random values.

Source

pub fn mod_u8(&self, n: u8) -> u8

Generates a random u8 value in range (0..n).

§Notice

This has a very slight bias. Use Rng::range_u8() instead for no bias.

Source

pub fn mod_u16(&self, n: u16) -> u16

Generates a random u16 value in range (0..n).

§Notice

This has a very slight bias. Use Rng::range_u16() instead for no bias.

Source

pub fn mod_u32(&self, n: u32) -> u32

Generates a random u32 value in range (0..n).

§Notice

This has a very slight bias. Use Rng::range_u32() instead for no bias.

Source

pub fn mod_u64(&self, n: u64) -> u64

Generates a random u64 value in range (0..n).

§Notice

This has a very slight bias. Use Rng::range_u64() instead for no bias.

Source

pub fn mod_usize(&self, n: usize) -> usize

Available on 64-bit only.

Generates a random usize value in range (0..n).

§Notice

This has a very slight bias. Use Rng::range_usize() instead for no bias.

Source

pub fn range_u8<T: RangeBounds<u8>>(&self, range: T) -> u8

Generates a random u8 value in the given range.

Source

pub fn range_u16<T: RangeBounds<u16>>(&self, range: T) -> u16

Generates a random u16 value in the given range.

Source

pub fn range_u32<T: RangeBounds<u32>>(&self, range: T) -> u32

Generates a random u32 value in the given range.

Source

pub fn range_u64<T: RangeBounds<u64>>(&self, range: T) -> u64

Generates a random u64 value in the given range.

Source

pub fn range_usize<T: RangeBounds<usize>>(&self, range: T) -> usize

Generates a random usize value in the given range.

Source

pub fn range_i8<T: RangeBounds<i8>>(&self, range: T) -> i8

Generates a random i8 value in the given range.

Source

pub fn range_i16<T: RangeBounds<i16>>(&self, range: T) -> i16

Generates a random i16 value in the given range.

Source

pub fn range_i32<T: RangeBounds<i32>>(&self, range: T) -> i32

Generates a random i32 value in the given range.

Source

pub fn range_i64<T: RangeBounds<i64>>(&self, range: T) -> i64

Generates a random i64 value in the given range.

Source

pub fn range_isize<T: RangeBounds<isize>>(&self, range: T) -> isize

Generates a random isize value in the given range.

Trait Implementations§

Source§

impl Default for Rng

Source§

fn default() -> Self

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

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