你好,我想请问c语言编写随机产生一百个整数的原理或者伪代码是什么?第一次接触过。
rand()函数原型
int rand(void);
功能
rand uses a multiplicative congruential random number generator with period 2 to the 32nd power to return successive pseudo-random numbers in the range from 0 to RAND_MAX. The symbolic constant RAND_MAX is defined in stdlib.h.
例子
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void)
{
int i;
time_t t;
srand((unsigned) time(&t)); //初始化随机数种子,没有这个,每次运行的随机数会相同的
printf("Ten random numbers from 0 to 99 ");
for(i=0; i<10; i++)
printf("%d ", rand() % 100); //生成0~99的随机数
return 0;
}
上一篇:温度传感器怎么接PLC?
热门标签: