1) arc4random () is more accurate and does not need to be generated immediately.
Usage:
The code for getting an integer between 0 and X-1 through arc4random () is as follows:
IntValue=Arc4random ()%X;
The code for getting an integer between 1 and x is as follows:
IntValue=(Arc4random ()%X)+1;
2). It is used in CCRANDOM_0_1 () cocos2d and the range is [0, 1].
Usage:
Float random = CCRANDOM_0_1 () * 5; // [] CCRANDOM_0_1 () value range: []
3) set the seed when random () needs Initialization
Usage:
Srandom (unsigned int) time (time_t *) NULL); // set the seed during initialization.
4). arc4random_uniform
During the development of iOS games, I always felt that there was a problem with the random number produced by arc4random, and the resulting values were not balanced. Today, we finally found another arc4random_uniform function, which is also in the C standard library. This problem is improved and a balanced random number is generated. Therefore, it is replaced globally.