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?
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)") value attribute, and perform some kind of mathematical operation to combine them all into one number. You could just add them all together, but that would mean that anagrams of the same string would have the same seed value - play around with it and I'm sure you can come up with a reasonable solution.srandom() and random() seem to be preferable.