In the application application:
- (void) applicationDidFinishLaunching:(UIApplication *)application { srandom(time(NULL));
The reason for this is because pseudo-random number generators require an initial or initial value. Using time, you are more likely to get different sequences of "random" numbers at each execution.
If you do not specify an initial value, the same seed is used for each execution, which gives the same sequence. This is usually undesirable behavior, but in some cases it is useful to be able to generate the same sequence, for example, for testing algorithms.
In most cases, you need to specify an initial value that will vary between runs, where the current time comes in handy.
Alex reynolds
source share