Run the following program:
#include <cstdlib> using std::rand; #include <iostream> using std::cout; int main() { cout << rand() << ' ' << rand() << ' ' << rand() << '\n'; }
Due to rand
, producing the same values ββuntil the seed is changed using srand
, this should produce three identical numbers.
eg.
567 567 567
However, when I run this program, it gives me three different meanings.
eg.
6334 18467 41
When the program (compiled and) starts again, the same three numbers are generated. Should I use srand
to change the seed before starting to get different results from rand
? Is this just my compiler / implementation trying to do me a favor?
OS: Windows XP
Compiler: GCC 4.6.2
Libraries: MinGW
EDIT: Trying to use srand
, I found that this is the result from seed 1 (which I assume is made by default).
chris source share