C++ 随机数的生成

此文件是随机生成10个0~100的数

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main()
{
    int i,j;
    srand((unsigned)time(NULL));  //生成随机种子
    for(i=0;i<10;i++)
    {
        j = rand()%100;  //指定生成随机数的范围为0~100
        cout<<j<<endl;
    }
}

运行结果:

猜你喜欢

转载自www.cnblogs.com/caozewen/p/12175250.html