Advertisement
Guest User

adl

a guest
Oct 12th, 2009
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. inline int next(int x0) // next element of the sequence
  7. {
  8.     return (214013*x0 + 2531011); // some magic numbers from wikipedia
  9. }
  10.  
  11.  
  12. inline int random(int x0)
  13. {
  14.     return (next(x0) & 0x7FFF0000) >> 16;
  15. }
  16.  
  17.  
  18. int main()
  19. {
  20.     int a, b, c;
  21.     scanf("%d %d %d", &a, &b, &c); // read 3 first numbers from the sequence
  22.    
  23.     int x0;
  24.     for (int i = 0x0000; i < 0xFFFF; i++) // small, but still brute force
  25.     {
  26.         x0 = (a << 16) | i; // new candidate
  27.         if (b == random(x0) && c == random(next(x0))) // we found our element, comparing only with b gives 50% success rate
  28.         {
  29.             break;
  30.         }
  31.     }
  32.  
  33.     x0 = next(x0);
  34.     for (;;) // and the 'random' sequence follows...
  35.     {
  36.         getchar();
  37.         x0 = next(x0);
  38.         printf("%d", random(x0));
  39.     }
  40.  
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement