Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Random float value within range.
extension ClosedRange where Bound: BinaryFloatingPoint {
var random: Bound {
let ratio = Bound(arc4random_uniform(UInt32.max)) / Bound(UInt32.max - 1)
let offset = (upperBound - lowerBound) * ratio
return lowerBound + offset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment