Struct Random

Source
pub struct Random {
    pub state: State,
}
Expand description

An implementation of Unity’s seeded PRNG, which aims to be faster than .NET’s System.Random.

Fields§

§state: State

Gets or sets the full internal state of the random number generator.

Implementations§

Source§

impl Random

Source

pub fn new() -> Random

Initializes the PRNG with the current time.

Source

pub fn init_state(&mut self, seed: i32)

(Re)-initializes the PRNG with a given seed.

Source

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

Returns a random i32 within [min..max].

Minimum is inclusive, maximum is exclusive.

Source

pub fn range_float(&mut self, min: f32, max: f32) -> f32

Returns a random f32 within [min..max] (range is inclusive).

Source

pub fn value(&mut self) -> f32

Returns a random f32 within [0..1] (range is inclusive).

Source

pub fn inside_unit_circle(&mut self) -> (f32, f32)

Returns a random point inside or on a circle with radius 1.0.

Note that the probability space includes the perimeter of the circle because next_f32, which is inclusive to 1.0, is used to acquire a random radius.

Source

pub fn on_unit_sphere(&mut self) -> (f32, f32, f32)

Returns a random point on the surface of a sphere with radius 1.0.

Source

pub fn inside_unit_sphere(&mut self) -> (f32, f32, f32)

Returns a random point inside or on a sphere with radius 1.0.

Note that the probability space includes the surface of the sphere because next_f32, which is inclusive to 1.0, is used to acquire a random radius.

Source

pub fn rotation(&mut self) -> (f32, f32, f32, f32)

Returns a random rotation.

Randomize the x, y, z, and w of a Quaternion each to [-1.0..1.0] (inclusive) via Range and normalize the result.

See also rotation_uniform for a slower but higher quality algorithm.

Source

pub fn rotation_uniform(&mut self) -> (f32, f32, f32, f32)

Returns a random rotation with uniform distribution.

Employs Hopf fibration to return a random Quaternion within a uniformly distributed selection space.

Gives higher quality results compared to the more naive approach employed by rotation, though at a 40% performance cost.

Source

pub fn color(&mut self) -> (f32, f32, f32, f32)

Generates a random RGBA color.

This may produce inaccurate results due to an issue with .NET versions before 5.x.

Unity uses a custom build of Mono, which is based on an older .NET version.

Source

pub fn color_h(&mut self, hue_min: f32, hue_max: f32) -> (f32, f32, f32, f32)

Generates a random RGBA color from hue ranges.

This may produce inaccurate results due to an issue with .NET versions before 5.x.

Unity uses a custom build of Mono, which is based on an older .NET version.

Source

pub fn color_hs( &mut self, hue_min: f32, hue_max: f32, saturation_min: f32, saturation_max: f32, ) -> (f32, f32, f32, f32)

Generates a random RGBA color from hue and saturation ranges.

This may produce inaccurate results due to an issue with .NET versions before 5.x.

Unity uses a custom build of Mono, which is based on an older .NET version.

Source

pub fn color_hsv( &mut self, hue_min: f32, hue_max: f32, saturation_min: f32, saturation_max: f32, value_min: f32, value_max: f32, ) -> (f32, f32, f32, f32)

Generates a random RGBA color from HSV ranges.

This may produce inaccurate results due to an issue with .NET versions before 5.x.

Unity uses a custom build of Mono, which is based on an older .NET version.

Source

pub fn color_hsva( &mut self, hue_min: f32, hue_max: f32, saturation_min: f32, saturation_max: f32, value_min: f32, value_max: f32, alpha_min: f32, alpha_max: f32, ) -> (f32, f32, f32, f32)

Generates a random RGBA color from HSV and alpha ranges.

This may produce inaccurate results due to an issue with .NET versions before 5.x.

Unity uses a custom build of Mono, which is based on an older .NET version.

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