srand+rand() combination
Posted defoliate
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了srand+rand() combination相关的知识,希望对你有一定的参考价值。
#include <iostream> #include <cstdlib> /* include to allow rand() to be used */ #include<ctime>/*just used in function: time(NULL)*/ using namespace std; int main() { int x; /* variable to hold our random integer */ srand(time(NULL));//system‘s time, in seconds,if not, the value will not change x = rand(); cout << "x = " << x << endl; x = rand(); cout << "x = " << x << endl; return 0; }
以上是关于srand+rand() combination的主要内容,如果未能解决你的问题,请参考以下文章
`rand()` 的用处 - 或者谁应该调用 `srand()`?