Quote:
Originally Posted by PhillipJames
I am also a new programmer and every time it runs, I get the same order of answers - I have put 6 values in the array and they appear - 6, 3, 5, 5, 6, 2, 3, 5, 2, 4 ......
I can close the sim, recompile and sure enough they appear in this order everytime.
Any ideas?
|
Yes - random() is actually a pseudorandom number generator. It starts with a "seed" value, and always generates the same set of numbers from that seed. Sooooo... the trick is to pick a different "seed" every time you start the program. The most common way to to do that is by using the current date+time as the seed; then you should get a different sequence every time.
Try this at the beginning of your program; say, in applicationDidFinishLaunching:
srandom (time (0));
BTW, don't get fancy about calling random() more than once, or multiplying two random number to get an even-more-random number, etc - you'd actually be removing randomness, not increasing it.