Type Method

sharedRandom()

Returns a shared instance that shares a system-wide random source.

Declaration

class func sharedRandom() -> GKRandomSource

Return Value

The shared system random source.

Discussion

The system random source shares state with the arc4random family of C functions. Generating random numbers with this source modifies the outcome of future calls to those functions, and calling those functions modifies the sequence of random values generated by this source. As such, this source is neither deterministic nor independent—use it only for trivial gameplay mechanics that do not rely on those attributes.

To instead use an independent random source, create an instance of one of the GKRandomSource subclasses. The GKARC4RandomSource class employs a similar algorithm but is independent from the system random source.