home *** CD-ROM | disk | FTP | other *** search
- package java.util;
-
- public class Random {
- private long seed;
- private static final long multiplier = 25214903917L;
- private static final long addend = 11L;
- private static final long mask = (1L << 48) - 1L;
- private double nextNextGaussian;
- private boolean haveNextNextGaussian;
-
- public Random() {
- this(System.currentTimeMillis());
- }
-
- public Random(long seed) {
- this.haveNextNextGaussian = false;
- this.setSeed(seed);
- this.haveNextNextGaussian = false;
- }
-
- public synchronized void setSeed(long seed) {
- this.seed = (seed ^ 25214903917L) & mask;
- }
-
- private synchronized int next(int bits) {
- long nextseed = this.seed * 25214903917L + 11L & mask;
- this.seed = nextseed;
- return (int)(nextseed >>> 48 - bits);
- }
-
- public int nextInt() {
- return this.next(32);
- }
-
- public long nextLong() {
- return ((long)this.next(32) << 32) + (long)this.next(32);
- }
-
- public float nextFloat() {
- int i = this.next(30);
- return (float)i / 1.0737418E9F;
- }
-
- public double nextDouble() {
- long l = ((long)this.next(27) << 27) + (long)this.next(27);
- return (double)l / (double)(1L << 54);
- }
-
- public synchronized double nextGaussian() {
- if (this.haveNextNextGaussian) {
- this.haveNextNextGaussian = false;
- return this.nextNextGaussian;
- } else {
- double v1;
- double v2;
- double s;
- do {
- v1 = (double)2.0F * this.nextDouble() - (double)1.0F;
- v2 = (double)2.0F * this.nextDouble() - (double)1.0F;
- s = v1 * v1 + v2 * v2;
- } while(s >= (double)1.0F);
-
- double multiplier = Math.sqrt((double)-2.0F * Math.log(s) / s);
- this.nextNextGaussian = v2 * multiplier;
- this.haveNextNextGaussian = true;
- return v1 * multiplier;
- }
- }
- }
-