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 { ... }
}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§
Sourceunsafe fn nextInt(&self) -> NSInteger
unsafe fn nextInt(&self) -> NSInteger
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
Sourceunsafe fn nextIntWithUpperBound(&self, upper_bound: NSUInteger) -> NSUInteger
unsafe fn nextIntWithUpperBound(&self, upper_bound: NSUInteger) -> NSUInteger
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.
Sourceunsafe fn nextUniform(&self) -> c_float
unsafe fn nextUniform(&self) -> c_float
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
Sourceunsafe fn nextBool(&self) -> bool
unsafe fn nextBool(&self) -> bool
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
impl ProtocolType for dyn GKRandom
impl<T> ImplementedBy<T> for dyn GKRandom
Implementations on Foreign Types§
impl<T> GKRandom for ProtocolObject<T>
Implementors§
impl GKRandom for GKARC4RandomSource
impl GKRandom for GKGaussianDistribution
GKRandomDistribution only.impl GKRandom for GKLinearCongruentialRandomSource
impl GKRandom for GKMersenneTwisterRandomSource
impl GKRandom for GKRandomDistribution
GKRandomDistribution only.impl GKRandom for GKRandomSource
impl GKRandom for GKShuffledDistribution
GKRandomDistribution only.