Struct Random

Source
pub struct Random { /* private fields */ }

Implementations§

Source§

impl Random

Source

pub fn new(seed: u64) -> Self

Source

pub fn set_seed(&mut self, seed: u64)

Sets the seed to seed. This is equivalent to Random::new

Source

pub fn next(&mut self, bits: u8) -> i32

Steps the RNG, returning up to 48 bits.

§Panics

If the amount of requested bits is over 48, this function panics. Use next_i64/next_u64 instead, or multiple calls.

Source

pub fn next_bytes(&mut self, bytes: &mut [u8])

Fills the byte array with random bytes.

Source

pub fn next_i32(&mut self) -> i32

Returns a uniformly distributed signed 32-bit integer.

Source

pub fn next_u32(&mut self) -> u32

Returns a uniformly distributed unsigned 32-bit integer.

Source

pub fn next_i32_bound(&mut self, max: i32) -> i32

Returns a positive random number in the range [0, max), up to 2^31. The range of the return value is represented by the value 0 <= value < max. A maximum of less than 1 is invalid because then no value would satisfy the range.

§Panics

If max is less than 1, the function panics.

Source

pub fn next_u32_bound(&mut self, max: u32) -> u32

Returns a positive random number in the range [0, max), up to 2^31. The range of the return value is represented by the value 0 <= value < max. A maximum of 0 is invalid because then no value would satisfy the range. Maximums of 2^31 or greater are not supported in Java.

§Panics

If max reinterpreted as a signed 32-bit integer is less than 1, the function panics.

Source

pub fn next_i64(&mut self) -> i64

Returns a uniformly distributed signed 64-bit integer.

Source

pub fn next_u64(&mut self) -> u64

Returns a uniformly distributed unsigned 64-bit integer.

Source

pub fn next_bool(&mut self) -> bool

Returns a boolean value that has an equal chance of being true or false.

Source

pub fn next_f32(&mut self) -> f32

Returns a f32 uniformly distributed between 0.0 and 1.0.

Source

pub fn next_f64(&mut self) -> f64

Returns a f64 uniformly distributed between 0.0 and 1.0.

Source

pub fn next_gaussian(&mut self) -> f64

Returns a gaussian-distributed number with a mean of 0.0 and standard deviation of 1.0.

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

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§

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.