Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. //header file for the pseudorandom sequence
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. class pRandInt
  6. {
  7. public:
  8.  
  9. pRandInt();
  10.  
  11. //Default constructor with parameters
  12. pRandInt(int, int, int, int);
  13.  
  14. //intial number in pseudorandom sequence
  15. //permits the seed to be changed
  16. void setFirstNum(int);
  17.  
  18. //generate the next number in the pseudorandom sequence
  19. int getNextNum();
  20.  
  21. private:
  22. int newSeed;
  23. int newMulti;
  24. int newIncr;
  25. int newMod;
  26. };
  27.  
  28. //implementation file for the pseudorandom sequence
  29. #include "pRandInt.h"
  30.  
  31. pRandInt::pRandInt()
  32. {
  33. int newSeed = 0;
  34. const int newMulti = 40;
  35. const int newIncr = 725;
  36. const int newMod = 729;
  37. }
  38.  
  39. pRandInt::pRandInt(int seed, int multi, int incr, int mod)
  40. {
  41. newSeed = seed;
  42. newMulti = multi;
  43. newIncr = incr;
  44. newMod = mod;
  45. }
  46.  
  47. void pRandInt::setFirstNum(int seed)
  48. {
  49. newSeed = seed;
  50. }
  51.  
  52. int pRandInt::getNextNum()
  53. {
  54. return (newMulti * newSeed + newIncr) % newMod;
  55. }
  56.  
  57. //main test file for the pseudorandom sequence
  58. #include <iostream>
  59. #include "pRandInt.h"
  60.  
  61. using namespace std;
  62.  
  63. int main()
  64.  
  65. {
  66. int seed = 0;
  67.  
  68. pRandInt num;
  69.  
  70. num.setFirstNum(seed);
  71.  
  72. cout << "The first number in your sequence is: ";
  73. cin >> seed;
  74.  
  75. cout << "The other numbers in your sequence are: ";
  76. cout << num.getNextNum() << endl;
  77. system("pause");
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement