/**************************************************************** Copyright (C) : University of Michigan Project: NERS 544 - Class example File: mcrng64.cpp Purpose: An example of a multiplicative congruential random number generator in 64 bits Compiler: g++ -std=c99 -O mcrng64.cpp Programmer: Alex Bielajew Revision Date: 09/12/2016 ****************************************************************/ #include using namespace std; long long rand(long long in) {return 6364136223846793005*in;} // The magic multiplier 63...005 is cited by Knuth as "excellent" int main(void) { cout << "Starting seed = "; long long iFirst; cin >> iFirst; if (iFirst%2 == 0) { cout << "*** Starting seed must be an odd number. Exiting! ***\n"; return 1; } long long in = iFirst; in = rand(in); //Next in series unsigned long long i = 0; cout << iFirst << endl; while(in != iFirst) { if (i < 10) cout << in << endl; i = i + 1; in = rand(in); // Update long long N = 10000000; if (i%N == 0) cout << "." << flush; } while (in != iFirst); // Stops when repeats if (i < 2000000000) cout << "\n# loops = " << i + 1 << "\n\n"; else cout << "\n# loops = " << i << " + 1 = " << i + 1 << "\n\n"; cout << in << endl; for (long long i = 1; i <= 10; i = i + 1) { in = rand(in); cout << in << endl; } return 0; }