My app uses random numbers. I would like to seed the random number generator so that it won't be the same every time. How might I go about doing this?
EDIT:
What parameter do I give srand() to seed the random generator with the current time?
This works:
let time = UInt32(NSDate().timeIntervalSinceReferenceDate)
srand(time)
print("Random number: \(rand()%10)")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With