GKRandom

Trait GKRandom 

Source
pub unsafe trait GKRandom {
    // Provided methods
    unsafe fn nextInt(&self) -> NSInteger
       where Self: Sized + Message { ... }
    unsafe fn nextIntWithUpperBound(
        &self,
        upper_bound: NSUInteger,
    ) -> NSUInteger
       where Self: Sized + Message { ... }
    unsafe fn nextUniform(&self) -> c_float
       where Self: Sized + Message { ... }
    unsafe fn nextBool(&self) -> bool
       where Self: Sized + Message { ... }
}
Available on crate feature GKRandomSource only.
Expand description

A protocol for random sources that can generate random numbers. This is the minimal interface needed to consume random values from a source; concrete subclasses should be used for configuring the production of random values. The availability of deterministic random sources is critical to creating reliable gameplay mechanics. Ensure that systems that should not influence each other have unique random sources and avoid sharing sources unless absolutely needed.

This protocol allows you to provide custom random sources from classes that are not able to derive from GKRandomSource directly.

See also Apple’s documentation

Provided Methods§

Source

unsafe fn nextInt(&self) -> NSInteger
where Self: Sized + Message,

Returns the next integer in the random sequence and moves ahead to the next one. The value is in the range of [INT32_MIN, INT32_MAX]. The lower bits are not guaranteed to be random so please use another property for simple choices.

See: nextBool

See: nextUniform

Source

unsafe fn nextIntWithUpperBound(&self, upper_bound: NSUInteger) -> NSUInteger
where Self: Sized + Message,

Returns the next unsigned value in the random sequence that is less than upperBound. The value is in the range of [0, upperBound). Thus the value never equals or exceeeds upperBound. The unsigned nature and upper bound allows implementations to use logical shifts to return a value whose lower bits are more random than a similar call to nextInt.

This is used to implement nextBool and nextUniform by default.

Source

unsafe fn nextUniform(&self) -> c_float
where Self: Sized + Message,

Returns the next uniform float in the random sequence and moves ahead to the next one. The value is in the range of [0.0, 1.0]. There is no weighting across the range so remapping this with a curve may give the best sampling distribution for your algorithm.

By default this should be based on nextIntWithUpperBound:. Implementions may base it on another representation if needed.

See: nextIntWithUpperBound:

See: nextInt

Source

unsafe fn nextBool(&self) -> bool
where Self: Sized + Message,

Returns the next true or false value in the random sequence and moves ahead to the next one. The value is either nonzero (true) or zero (false). Use this for simple boolean switches in logic that don’t require fuzzy evaluation. For fuzzy evaluation use nextUniform.

By default this should be based on nextIntWithUpperBound:. Implementations may base it on another representation if needed.

See: nextIntWithUpperBound:

See: nextUniform

Trait Implementations§

Source§

impl ProtocolType for dyn GKRandom

Source§

const NAME: &'static str = "GKRandom"

The name of the Objective-C protocol that this type represents. Read more
Source§

fn protocol() -> Option<&'static AnyProtocol>

Get a reference to the Objective-C protocol object that this type represents. Read more
Source§

impl<T> ImplementedBy<T> for dyn GKRandom
where T: ?Sized + Message + GKRandom,

Implementations on Foreign Types§

Source§

impl<T> GKRandom for ProtocolObject<T>
where T: ?Sized + GKRandom,

Implementors§

Source§

impl GKRandom for GKARC4RandomSource

Source§

impl GKRandom for GKGaussianDistribution

Available on crate feature GKRandomDistribution only.
Source§

impl GKRandom for GKLinearCongruentialRandomSource

Source§

impl GKRandom for GKMersenneTwisterRandomSource

Source§

impl GKRandom for GKRandomDistribution

Available on crate feature GKRandomDistribution only.
Source§

impl GKRandom for GKRandomSource

Source§

impl GKRandom for GKShuffledDistribution

Available on crate feature GKRandomDistribution only.