Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. long seed = System.nanoTime();
  2. seed ^= (seed << 21);
  3. seed ^= (seed >>> 35);
  4. seed ^= (seed << 4);
  5.  
  6. public int random(int max){ /*...*/}
  7.  
  8. public class XORShiftRandom {
  9.  
  10. private long last;
  11.  
  12. public XORShiftRandom() {
  13. this(System.currentTimeMillis());
  14. }
  15.  
  16. public XORShiftRandom(long seed) {
  17. this.last = seed;
  18. }
  19.  
  20. public int nextInt(int max) {
  21. last ^= (last << 21);
  22. last ^= (last >>> 35);
  23. last ^= (last << 4);
  24. int out = (int) last % max;
  25. return (out < 0) ? -out : out;
  26. }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement