Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. // Allowed are all branch-statements, loop-statements, and functions.
  2. // The program must comply exactly to the structured paradigm, hence struct and class are forbidden.
  3. // Because of the adherence to structured paradigm command X is strictly forbidden!
  4.  
  5. #include <iostream> // required for console input and output
  6. #include <chrono> //required for getting system time
  7.  
  8. using namespace std; // allows unqualified use of identifiers of namespace std
  9.  
  10. bool ask_yn(const char * msg) {
  11.     cout << msg << " (y/n)? " << flush;
  12.     char answer;
  13.     cin >> answer;
  14.     if (answer == 'y' || answer == 'Y')
  15.         return true;
  16.     else return false;
  17. }
  18.  
  19. unsigned long int max = 1000,
  20.                   factor = 623,
  21.                   increment = 525,
  22.                   start = 157,
  23.                   actualrandom = ((factor * start) + increment) % max;;
  24.  
  25. unsigned int long random_number() {
  26.     actualrandom = ((factor * actualrandom) + increment) % ::max;
  27.     return actualrandom;
  28. }
  29.  
  30. void random_seed() {
  31.     // the following function calls retrieve system time and cast it to milliseconds
  32.     actualrandom =  chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
  33. }
  34.  
  35. int main(int argc, const char * argv[]) {
  36.     if (ask_yn("Random seed the generator") == true)
  37.         random_seed();
  38.     do {
  39.         cout << random_number() << endl;
  40.     } while (ask_yn("Another random number") == true);
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement