问题
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?
回答1:
This works:
let time = UInt32(NSDate().timeIntervalSinceReferenceDate)
srand(time)
print("Random number: \(rand()%10)")
来源:https://stackoverflow.com/questions/25895081/how-does-one-seed-the-random-number-generator-in-swift