Returns a random value within the specified range, using the given generator as a source for randomness.
SDK
- Xcode 10.0+
Framework
- Swift Standard Library
Declaration
Parameters
range
The range in which to create a random value.
range
must not be empty.generator
The random number generator to use when creating the new random value.
Return Value
A random value within the bounds of range
.
Discussion
Use this method to generate an integer within a specific range when you are using a custom random number generator. This example creates three new values in the range 1..<100
.
Note
The algorithm used to create random values may change in a future version of Swift. If you’re passing a generator that results in the same sequence of integer values each time you run your program, that sequence may change when your program is compiled using a different version of Swift.