/** * Creates a new random number generator using a single {@code long} seed. * The seed is the initial value of the internal state of the pseudorandom * number generator which is maintained by method {@link #next}. * * <p>The invocation {@code new Random(seed)} is equivalent to: * <pre> {@code * Random rnd = new Random(); * rnd.setSeed(seed);}</pre> * * @param seed the initial seed * @see #setSeed(long) */ public Random(long seed) { this.seed = initialScramble(seed); }
/** * Creates a new random number generator using a single {@code long} seed. * The seed is the initial value of the internal state of the pseudorandom * number generator which is maintained by method {@link #next}. * * <p>The invocation {@code new Random(seed)} is equivalent to: * <pre> {@code * Random rnd = new Random(); * rnd.setSeed(seed);}</pre> * * @param seed the initial seed * @see #setSeed(long) */ public Random(long seed) { this.seed = initialScramble(seed); }
/** * Sets the seed of this random number generator using a single * {@code long} seed. The general contract of {@code setSeed} is * that it alters the state of this random number generator object * so as to be in exactly the same state as if it had just been * created with the argument {@code seed} as a seed. The method * {@code setSeed} is implemented by class {@code Random} by * atomically updating the seed to * <pre>{@code (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1)}</pre> * and clearing the {@code haveNextNextGaussian} flag used by {@link * #nextGaussian}. * * <p>The implementation of {@code setSeed} by class {@code Random} * happens to use only 48 bits of the given seed. In general, however, * an overriding method may use all 64 bits of the {@code long} * argument as a seed value. * * @param seed the initial seed */ synchronized public void setSeed(long seed) { this.seed = initialScramble(seed); haveNextNextGaussian = false; }
/** * Sets the seed of this random number generator using a single * {@code long} seed. The general contract of {@code setSeed} is * that it alters the state of this random number generator object * so as to be in exactly the same state as if it had just been * created with the argument {@code seed} as a seed. The method * {@code setSeed} is implemented by class {@code Random} by * atomically updating the seed to * <pre>{@code (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1)}</pre> * and clearing the {@code haveNextNextGaussian} flag used by {@link * #nextGaussian}. * * <p>The implementation of {@code setSeed} by class {@code Random} * happens to use only 48 bits of the given seed. In general, however, * an overriding method may use all 64 bits of the {@code long} * argument as a seed value. * * @param seed the initial seed */ synchronized public void setSeed(long seed) { this.seed = initialScramble(seed); haveNextNextGaussian = false; }
public class RandomCustom extends Random{ //You have to Override this aswell. @Override synchronized public void setSeed(long seed) { this.seed.set(initialScramble(seed)); haveNextNextGaussian = false; } @Override protected int next(int bits){ long oldseed, nextseed; AtomicLong seed = this.seed; do { oldseed = seed.get(); nextseed = (oldseed * fact + constant) & modulus; } while (!seed.compareAndSet(oldseed, nextseed)); return (int)(nextseed >>> (48 - bits)); } }