rand&&srand

rand()

功能:伪随机数发生器

库: stdlib.h

用法:需要先调用srand初始化,一般用当前日期初始化随机数种子,

     这样每次执行代码都可以产生不同的随机数。

 

View Code
#include "iostream"

#include "cstdio"

#include "ctime"

using namespace std;



int main()

{

    srand((unsigned)time(NULL));

    for(int i=0; i<20; i++)

    {

        cout<<rand()%10<<endl;

    }

}

你可能感兴趣的:(&&)