Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long seed = System.nanoTime();
- seed ^= (seed << 21);
- seed ^= (seed >>> 35);
- seed ^= (seed << 4);
- public int random(int max){ /*...*/}
- public class XORShiftRandom {
- private long last;
- public XORShiftRandom() {
- this(System.currentTimeMillis());
- }
- public XORShiftRandom(long seed) {
- this.last = seed;
- }
- public int nextInt(int max) {
- last ^= (last << 21);
- last ^= (last >>> 35);
- last ^= (last << 4);
- int out = (int) last % max;
- return (out < 0) ? -out : out;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement