com.emc.mongoose.common.math.Random Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mongoose-common Show documentation
Show all versions of mongoose-common Show documentation
Mongoose is a high-load storage performance testing tool
The newest version!
package com.emc.mongoose.common.math;
import static com.emc.mongoose.common.math.MathUtil.xorShift;
public final class Random {
private static final double DOUBLE_UNIT = 0x1.0p-53;
private long seed;
public Random() {
reset();
}
public void reset() {
seed = System.nanoTime() ^ System.currentTimeMillis();
}
public Random(final long seed) {
this.seed = seed;
}
public final long nextLong() {
return seed = xorShift(seed);
}
public final long nextLong(final long range) {
return Math.abs(nextLong() % range);
}
public final int nextInt() {
return (int) nextLong();
}
public final int nextInt(final int range) {
return (int) nextLong(range);
}
public final double nextDouble() {
seed = xorShift(seed);
return (((seed >>> 22) << 27) + (seed >>> 21)) * DOUBLE_UNIT;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy