Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //header file for the pseudorandom sequence
- #include<iostream>
- using namespace std;
- class pRandInt
- {
- public:
- pRandInt();
- //Default constructor with parameters
- pRandInt(int, int, int, int);
- //intial number in pseudorandom sequence
- //permits the seed to be changed
- void setFirstNum(int);
- //generate the next number in the pseudorandom sequence
- int getNextNum();
- private:
- int newSeed;
- int newMulti;
- int newIncr;
- int newMod;
- };
- //implementation file for the pseudorandom sequence
- #include "pRandInt.h"
- pRandInt::pRandInt()
- {
- int newSeed = 0;
- const int newMulti = 40;
- const int newIncr = 725;
- const int newMod = 729;
- }
- pRandInt::pRandInt(int seed, int multi, int incr, int mod)
- {
- newSeed = seed;
- newMulti = multi;
- newIncr = incr;
- newMod = mod;
- }
- void pRandInt::setFirstNum(int seed)
- {
- newSeed = seed;
- }
- int pRandInt::getNextNum()
- {
- return (newMulti * newSeed + newIncr) % newMod;
- }
- //main test file for the pseudorandom sequence
- #include <iostream>
- #include "pRandInt.h"
- using namespace std;
- int main()
- {
- int seed = 0;
- pRandInt num;
- num.setFirstNum(seed);
- cout << "The first number in your sequence is: ";
- cin >> seed;
- cout << "The other numbers in your sequence are: ";
- cout << num.getNextNum() << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement