Reputation: 2781
Using Swift 4.2, I get the title as an error in this function:
func jitter(range: Int) -> Int {
return Int.random(in: 0..<range, using: SystemRandomNumberGenerator())
}
Questions:
Upvotes: 0
Views: 599
Reputation: 135588
The Swift compiler is giving you a bad error message. The problem is that the second argument to Int.random(in:using:)
must be passed inout
(i.e. with a &
prefix). This works:
func jitter(range: Int) -> Int {
var rng = SystemRandomNumberGenerator()
return Int.random(in: 0..<range, using: &rng)
}
Even easier, omit the using:
parameter altogether (SystemRandomNumberGenerator
is the default RNG anyway):
func jitter(range: Int) -> Int {
return Int.random(in: 0..<range)
}
Upvotes: 1