|
From: <and...@su...> - 2003-06-19 03:55:10
|
Dear users,
Regardless the intresting observations of bad randomness of the function
rand(), I have a doubt too.
Please consider the following piece of code:
1 -...
2- #include <iostream>
3 -#include <ctime>
4 -#include <cstdlib>
5 -...
6 -int main()
7 -{
8 - int a;
9 -
10 - srand(time(0));
11- for(int i=0; i<1000; i++)
12- {
13- cout << rand()%1000+1 << endl;
14- }
15- ...
16-}
A)I use the argument of line 10 calling srand to make sure that the current
time
gives me a safe different seed for srand;
B)So, my command in line 13 will print 1000 numbers between 1 and 1000;
My doubt:
Will my cout on line 13 print 1000 ***DIFFERENT*** numbers? I don´t think
so!
This is C++ code
Regards
Andre
|