Advertisement
Guest User

rand implementation

a guest
May 6th, 2012
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int seed;
  5.  
  6. void _srand(int x) {
  7.     seed = x;
  8. }
  9.  
  10. int _rand(){
  11.     return (((seed = seed * 214013L + 2531011L) >> 16) & 0x7fff);
  12. }
  13.  
  14. int main(){
  15.  
  16.     srand(123);
  17.     for (int i = 0; i < 10;i++) printf("%d ", rand());
  18.     puts("");
  19.  
  20.     _srand(123);
  21.     for (int i = 0; i < 10;i++) printf("%d ", _rand());
  22.     puts("");
  23.  
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement