Functions
The following functions are available globally.
-
Returns a random number in the given range, inclusive.
Declaration
Swift
public func random(from: Int, to: Int) -> IntParameters
fromThe lowest possible random value that may be returned.
toThe highest possible random value that may be returned.
-
Re-maps a number from one range to another.
Numbers outside of the range are not clamped to the minimum and maximum parameters values, because out-of-range values are often intentional and useful.
Experiment
When the value given is 2, and the current range is from 0 to 5, what do you expect the return value to be when mapped to a target range of 0 to 50? Try it, and find out:let result = map(value: 2, fromLower: 0, fromUpper: 5, toLower: 0, toUpper: 50)Declaration
Swift
public func map(value : Double, fromLower : Double, fromUpper : Double, toLower : Double, toUpper : Double) -> DoubleParameters
valuethe incoming value to be converted
fromLowerlower bound of the value’s current range
fromUpperupper bound of the value’s current range
toLowerlower bound of the value’s target range
toUpperupper bound of the value’s target range
Return Value
The equivalent value in the target range
View on GitHub
Functions Reference