Protocol

GKRandom

The common interface for all randomization classes in (or usable with) GameplayKit.

Declaration

@protocol GKRandom

Overview

GameplayKit randomization classes include the GKRandomSource and GKRandomDistribution classes and their subclasses. You use those classes to generate random behavior for gameplay mechanics, and use this protocol type directly when composing random sources to create more complex randomizers.

For more information on choosing and using randomizers in GameplayKit, read Randomization in GameplayKit Programming Guide.

Topics

Generating Random Numbers

- nextInt

Generates and returns a new random integer.

Required.

- nextIntWithUpperBound:

Generates and returns a new random integer less than the specified limit.

Required.

- nextUniform

Generates and returns a new random floating-point value.

Required.

- nextBool

Generates and returns a new random Boolean value.

Required.

Relationships

See Also

Randomization

GKRandomSource

The superclass for all basic randomization classes in GameplayKit.

GKARC4RandomSource

A basic random number generator implementing the ARC4 algorithm, which is suitable for most gameplay mechanics.

GKLinearCongruentialRandomSource

A basic random number generator implementing the linear congruential generator algorithm, which is faster but less random than the default random source.

GKMersenneTwisterRandomSource

A basic random number generator implementing the Mersenne Twister algorithm, which is more random, but slower than the default random source.

GKRandomDistribution

A generator for random numbers that fall within a specific range and that exhibit a specific distribution over multiple samplings.

GKGaussianDistribution

A generator for random numbers that follow a Gaussian distribution (also known as a normal distribution) across multiple samplings.

GKShuffledDistribution

A generator for random numbers that are uniformly distributed across many samplings, but where short sequences of similar values are unlikely.