Skip to main content

Random

Struct Random 

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

The game’s random number generator. See the module documentation.

Implementations§

§

impl Random

pub fn new(seed: u32) -> Random

A generator seeded with seed, as the engine seeds one.

Original: Random::Random(unsigned int), Runtime 0x1800ca740.

pub fn from_parts(index: u32, state: [u32; 624]) -> Random

A generator restored from a save: its index, then its 624 state words.

pub fn index(&self) -> u32

The position of the next word in the state.

pub fn state(&self) -> &[u32; 624]

The 624 state words.

pub fn rand(&mut self) -> u32

The next number, any u32.

Original: Rand(), Runtime 0x1800ca800.

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

A number from 0 to n - 1. When n is 0, it returns 0 and draws nothing.

Original: Rand(unsigned int), Runtime 0x1800ca8b0.

pub fn rand_range(&mut self, lo: i32, hi: i32) -> i32

A number from lo to hi, both included.

Original: Rand(int, int), Runtime 0x1800ca5e0.

pub fn rand_tol(&mut self, t: i32) -> i32

A number from -t to t, both included.

Original: RandTol(int), Runtime 0x1800ca610.

pub fn rand_float(&mut self) -> f32

A float from 0 to 1, 1 not included: (float)u × 2⁻³².

Original: RandFloat(), Runtime 0x1800ca5b0.

pub fn rand_float_tol(&mut self) -> f32

A float from -1 to 1, -1 not included: 1 − (float)u × 2⁻³² × 2.

Original: RandFloatTol(), Runtime 0x1800ca870.

Trait Implementations§

§

impl Clone for Random

§

fn clone(&self) -> Random

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
§

impl Debug for Random

§

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

Formats the value using the given formatter. Read more
§

impl Eq for Random

§

impl PartialEq for Random

§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
§

impl StructuralPartialEq for Random

Auto Trait Implementations§

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.