Protocol

GKRandom

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

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

func nextInt()

Generates and returns a new random integer.

Required.

func nextInt(upperBound: Int)

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

Required.

func nextUniform()

Generates and returns a new random floating-point value.

Required.

func nextBool()

Generates and returns a new random Boolean value.

Required.

Relationships

See Also

Randomization

class GKRandomSource

The superclass for all basic randomization classes in GameplayKit.

class GKARC4RandomSource

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

class GKLinearCongruentialRandomSource

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

class GKMersenneTwisterRandomSource

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

class GKRandomDistribution

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

class GKGaussianDistribution

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

class GKShuffledDistribution

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