Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. srand(time(NULL));
  2. digit = begin_num + rand() % n;
  3.  
  4. main
  5. {
  6. uint32_t stat[1];
  7. stat[0] = 2595719;
  8. uint32_t rang = 0;
  9. int min = 10;
  10. int max = 1000;
  11. for (int i = 0; i < 10000; i++)
  12. {
  13. rang = rand(stat) % (max - min) + min;
  14. cout << "Random Number is " << rang << endl;
  15. }
  16. }
  17.  
  18. uint32_t rand(uint32_t state[1])
  19. {
  20. uint32_t x = state[0];
  21. x ^= x << 13;
  22. x ^= x >> 17;
  23. x ^= x << 5;
  24. state[0] = x;
  25. return x;
  26. }
  27.  
  28. static unsigned long long int next = 1;
  29.  
  30. int rand(void) {
  31. next = next * 1103515245 + 12345;
  32. return (unsigned int)(next/65536) % 32768;
  33. }
  34.  
  35. void srand(unsigned int seed) {
  36. next = seed;
  37. }
  38.  
  39. class RandInt {
  40. using Cont = std::valarray<int>;
  41. Cont v;
  42. static int k;
  43. public:
  44. RandInt(int min, int max, size_t seed)
  45. {
  46. k = seed;
  47. int langht = max - min;
  48. v = Cont(min, langht);
  49. for (int i = 1; i < langht; ++i)
  50. v[i] = v[i -1] + 1;
  51.  
  52. }
  53. int operator ()()
  54. {
  55. v = v.cshift(k);
  56. ++k;
  57. return v[v.size()/2];
  58. }
  59. };
  60. int RandInt::k;
  61.  
  62. int main(])
  63. {
  64. RandInt r(-25, 25, 3);
  65. for (int i = 0; i < 20; ++i)
  66. std::cout << r() << 'n';
  67. return 0;
  68. }
  69.  
  70. class Random
  71. {
  72. public:
  73. typedef int RandomValue;
  74. Random& operator = (int seed) { X = seed; return *this; }
  75. Random(int seed = 1):X(seed){};
  76. int operator()(int seed = 0)
  77. {
  78. const int MM = 2147483647;
  79. const int AA = 48271;
  80. const int QQ = 44488;
  81. const int RR = 3399;
  82. if (seed != 0) X = seed;
  83. X = AA*(X%QQ)-RR*(X/QQ);
  84. if (X < 0) X += MM;
  85. return X-1;
  86. }
  87. int operator()(int min, int max)
  88. {
  89. return (*this)()%(max-min) + min;
  90. }
  91. private:
  92. int X;
  93. };
  94.  
  95. class Random64
  96. {
  97. typedef unsigned long long uint64;
  98. public:
  99. typedef uint64 RandomValue;
  100. Random64& operator = (uint64 seed) { X = seed; return *this; }
  101. Random64(uint64 seed = 0):X(seed){};
  102. uint64 operator()(uint64 seed = uint64(-1))
  103. {
  104. const uint64 a = 3202034522624059733ULL;
  105. const uint64 c = 1ULL;
  106.  
  107. if (seed != uint64(-1)) X = seed;
  108. uint64 Y = a * X + c;
  109. X = a * Y + c;
  110. Y = (Y&0xFFFFFFFF00000000ULL) | (X >> 32);
  111. return Y;
  112. }
  113. uint64 operator()(uint64 min, uint64 max)
  114. {
  115. return (*this)()%(max-min) + min;
  116. }
  117. private:
  118. uint64 X;
  119. };
Add Comment
Please, Sign In to add comment