【发布时间】:2011-07-01 13:56:49
【问题描述】:
这是一个小程序:
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
long x = rand();
cout << x << endl;
}
它总是显示41。但是如果我像这样修改程序,
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
for( int i = 0 ; i <= 9 ; i++ ) {
long x = rand();
cout << x << endl;
}
}
输出如预期。随机数集。 输出:
41
18467
6334
26500
19169
15724
11478
29358
26962
24464
但是为什么我在运行第一个程序时得到相同的数字rand实际上是如何工作的?
【问题讨论】:
标签: c++ visual-c++ random