C/C++中的srand()函数和rand()函数

一般要用到stdlib.h头文件,一定要用到time.h头文件。

这样输出的随机数看起来像那么回事:

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
    srand((unsigned) time(0));
    for(int k=0;k<50;k++)
    {
		int i=rand()%10;
		printf("%d\n",i); 
    }
}

猜你喜欢

转载自blog.csdn.net/m0_46606140/article/details/106772872
今日推荐