The superclass for all basic randomization classes in GameplayKit.
- iOS 9.0+
- macOS 10.11+
- tvOS 9.0+
In most cases you do not use this class directly; instead, use one of the subclasses listed below. On its own, a random source provides little control over the range or distribution of generated random numbers; to specify such options, use a random source in conjunction with one of the
When you create an instance of
GKRandom or one of its subclasses, 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 another instance, and that sequence can be replicated when necessary. For details on replicating sequences, see each of the random source classes.
Your choice of random source class determines the algorithm used for random number generation:
GKARC4Randomclass uses an algorithm similar to that employed in arc4random family of C functions. (However, instances of this class are independent from calls to the arc4random functions.)
GKLinearclass uses an algorithm that is faster, but less random, than the
Congruential Random Source
GKARC4Randomclass. (Specifically, the low bits of generated numbers repeat more often than the high bits.) Use this source when performance is more important than robust unpredictability.
GKMersenneclass uses an algorithm that is slower, but more random, than the
Twister Random Source
GKARC4Randomclass. Use this source when it’s important that your use of random numbers not show repeating patterns and performance is of less concern.