A basic random number generator implementing the ARC4 algorithm, which is suitable for most gameplay mechanics.
SDKs
- iOS 9.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
Framework
- Gameplay
Kit
Declaration
@interface GKARC4RandomSource : GKRandom Source
Overview
Important
The randomization services provided in GameplayKit are suitable for reliably creating deterministic, pseudorandom gameplay mechanics, but are not cryptographically robust. For cryptography, obfuscation, or cipher uses, use the Security framework, described in Cryptographic Services Guide.
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 GKRandom
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
initializer.
Note
The GKARC4Random
class uses a similar agorithm to, but is independent from, the arc4random family of C functions.
For more information on choosing and using randomizers in GameplayKit, read Randomization in GameplayKit Programming Guide.