Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. public class LCG {
  2. long a;
  3. long c;
  4. long m;
  5. long seed;
  6. long shift;
  7. public LCG(long _a, long _c, long _m, long seed) {
  8. this.a = _a;
  9. this.c = _c;
  10. this.m = _m;
  11. this.seed = seed;
  12. }
  13. public LCG(long _a, long _c, long _m, long seed, long _shift) {
  14. this.a = _a;
  15. this.c = _c;
  16. this.m = _m;
  17. this.seed = seed;
  18. this.shift = _shift;
  19. }
  20. public long next() {
  21.  
  22. long x = (a*this.seed+c)%m ;
  23. if (x < 0)
  24. x= x+m;
  25. System.out.println(x);
  26. seed(x);
  27. x = (x >> this.shift);
  28. return x;
  29. }
  30. public void seed(long seed) {
  31. this.seed = seed;
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement