Dalibor Dalibor - 3 months ago 6x
Swift Question

Generate a random double between -1 and 1 in Swift

This one should be quite simple but somehow I can't find a way to do this:
I have to get a random double between -1 and 1.

Everything I found on the internet was either for Integers, from 0 to 1 or didn't work.

I hope some of you guys can help me!

Hoa Hoa
let a = (Double(arc4random()) / Double(UInt32.max)) * 2 - 1

PS: use UInt32.max for a Swifty code ;)