Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Allowed are all branch-statements, loop-statements, and functions.
- // The program must comply exactly to the structured paradigm, hence struct and class are forbidden.
- // Because of the adherence to structured paradigm command X is strictly forbidden!
- #include <iostream> // required for console input and output
- #include <chrono> //required for getting system time
- using namespace std; // allows unqualified use of identifiers of namespace std
- bool ask_yn(const char * msg) {
- cout << msg << " (y/n)? " << flush;
- char answer;
- cin >> answer;
- if (answer == 'y' || answer == 'Y')
- return true;
- else return false;
- }
- unsigned long int max = 1000,
- factor = 623,
- increment = 525,
- start = 157,
- actualrandom = ((factor * start) + increment) % max;;
- unsigned int long random_number() {
- actualrandom = ((factor * actualrandom) + increment) % ::max;
- return actualrandom;
- }
- void random_seed() {
- // the following function calls retrieve system time and cast it to milliseconds
- actualrandom = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
- }
- int main(int argc, const char * argv[]) {
- if (ask_yn("Random seed the generator") == true)
- random_seed();
- do {
- cout << random_number() << endl;
- } while (ask_yn("Another random number") == true);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement