3

Rand

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. int main() {
  6.     using namespace std;
  7.  
  8.     unsigned seed;
  9.     unsigned min, max, range;
  10.  
  11.     cout << "RAND_MAX = " << RAND_MAX << endl;
  12.  
  13.     cout << "Enter a min and a max (integers): ";
  14.     cin >> min >> max;
  15.     range = max - min + 1;
  16.  
  17.     seed = time( 0 );
  18.     cout << "seed=" << seed << endl;
  19.     srand( seed );
  20.     for ( int i = 0; i < 8; i++ )
  21.         cout << rand()/100%range + min << endl;
  22.  
  23.     cout << "Enter a seed (integer): ";
  24.     cin >> seed;
  25.     srand( seed );
  26.     for ( int i = 0; i < 8; i++ )
  27.         cout << rand()/100%range + min << endl;
  28. }

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].