/* RAND.C: This program seeds the random-number generator
* with the GetTickCount, then displays 10 random integers.
*/
//改编自msdn
#include <stdlib.h>
#include <stdio.h>
#include <winbase.h>
void main( void )
{
int i;
/* Seed the random-number generator with GetTickCount so that
the numbers will be different every time we run.
*/
//srand()函数产生一个以当前时间开始的随机种子
srand(GetTickCount());
/* Display 10 numbers. */
for(i = 0;i < 10;i++ )
printf("%6d\n", rand()%9);//这里表示产生0~9的随机数
}
C++随机数产生代码
最新推荐文章于 2024-08-02 07:40:29 发布