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


To generate basic random values with this random source, use the methods defined in the GKRandom protocol. To generate random values with a specific range and distribution, use this random source with the GKRandomDistribution class or one of its subclasses.

When you create an instance of this class, the resulting random source is both independent and deterministic—that is, the sequence of numbers generated by one instance has no effect on the sequence generated by any other instance, and that sequence can be replicated when necessary. For details on replicating sequences, see the seed property and init(seed:) initializer.

The linear congruential random source uses the algorithm described by Donald E. Knuth in The Art of Computer Programming, Volume 2: Seminumerical Algorithms, section 3.2.1, with the common seed mask value of 0x5DEECE66D. This random source is therefore compatible with other implementations of that algorithm, including the java.util.Random class in Java. That is, if you initialize a GKLinearCongruentialRandomSource instance and a compatible implementation using the same seed value, both generate the same sequence of numbers.

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


Creating a Random Source


Initializes a random source from a nondeterministic seed.

init(seed: UInt64)

Initializes a random source with the specified seed value.

Replicating Random Behavior

var seed: UInt64

The seed value that determines the random source’s behavior.


Inherits From