00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00026 public class RanQD1 {
00027
00028 final static long MASK = 0xffffffffl;
00029 final static double MAX_INT = 4294967295.0;
00030 final static long A = 1664525l;
00031 final static long C = 1013904223l;
00032
00033 private long idum;
00034
00039 public RanQD1 (long seed) {
00040 idum = seed;
00041 nextLong();
00042 }
00043
00048 public void setSeed (long seed) {
00049 idum = seed;
00050 nextLong();
00051 }
00052
00056 public long nextLong () {
00057 idum = (A * idum + C) & MASK;
00058 return idum;
00059 }
00060
00064 public double nextDouble () {
00065 return nextLong()/MAX_INT;
00066 }
00067
00071 public int nextInt (int min, int max) {
00072 return min + (int) Math.floor(nextDouble()*(max-min+1));
00073 }
00074 }