谢谢作者: 云层 时间: 2011-10-19 17:01
1初始化随机
2.15-21作者: linlinxu 时间: 2011-10-20 10:26 回复 1#zhangchaoy
rand()函数是生成一个随机的非负整数函数。
Example 1
The following example generates a random number restricted to a specific zero-based range using the mod (%) operator.
//srand is called before rand
srand(time(NULL));
/* Generate a random number from 0-99 */
lr_output_message
("A number between 0 and 99: %d\n", rand() % 100);
Output:
Action.c(7): A number between 0 and 99: 72
Example 2
The following example generates a random number, rNum, between 20 and 29 using the mod (%) operator and addition.
int rNum;
//srand is called before rand
srand(time(NULL));
/* The order of evaluation is first rand(), then the modulus,
then the addition. The command below is equivalent to :