Global Function

random()

Declaration

func random(max: Double) -> Double
func random(min: Double, max: Double) -> Double

Parameters

min Lower limit for random value. In the version without a min argument, the min value is 0.
max Upper limit for random value. The returned value will always be less than this value.

Returns

Double

Description

Generates a random number. The number is generated using the GKLinearCongruentialRandomSource generator in the GameplayKit framework, using the sharedRandom source.

Examples

// n will be a random number in range [0,10)
let n = random(max: 10.0)

// m will be a random number in range [2,8)
let m = random(min:2.0, max: 8.0)

Related

remap()