Using the arc4random_uniform()
method, how should I assemble the logic to generate a random within a given range?
For example, given the range [5, 10]
Random Candidates:
5, 6, 7, 8, 9, 10
Using the arc4random_uniform()
method, how should I assemble the logic to generate a random within a given range?
For example, given the range [5, 10]
Random Candidates:
5, 6, 7, 8, 9, 10
Since the function allows you to determine the maximum, you only need to do a minimum offset.
arc4random_uniform(max - min) + min
In your example:
arc4random_uniform(5) + 5