3
Rand
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- int main() {
- using namespace std;
- unsigned seed;
- unsigned min, max, range;
- cout << "RAND_MAX = " << RAND_MAX << endl;
- cout << "Enter a min and a max (integers): ";
- cin >> min >> max;
- range = max - min + 1;
- seed = time( 0 );
- cout << "seed=" << seed << endl;
- srand( seed );
- for ( int i = 0; i < 8; i++ )
- cout << rand()/100%range + min << endl;
- cout << "Enter a seed (integer): ";
- cin >> seed;
- srand( seed );
- for ( int i = 0; i < 8; i++ )
- cout << rand()/100%range + min << endl;
- }
Comments