5 // Bob Smith (bob@thestuff.net)
7 // (C) 2001 Bob Smith. http://www.thestuff.net
11 using System.Globalization;
19 private const int A = 16807;
20 private const int M = 2147483647;
21 private const int Q = 127773;
22 private const int R = 2836;
26 S = (int)(DateTime.Now.Ticks);
29 public Random(int Seed)
34 public virtual int Next()
36 return (int)(this.Sample()*Int32.MaxValue);
39 public virtual int Next(int maxValue)
42 throw new ArgumentOutOfRangeException(Locale.GetText (
43 "Max value is less then min value."));
44 else if (maxValue == 0)
46 return (int)(this.Sample()*maxValue);
49 public virtual int Next(int minValue, int maxValue)
51 if (minValue > maxValue)
52 throw new ArgumentOutOfRangeException(Locale.GetText (
53 "Min value is greater then max value."));
54 else if (minValue == maxValue)
56 return (int)(this.Sample()*maxValue)+minValue;
58 public virtual void NextBytes(byte[] buffer)
62 throw new ArgumentNullException();
63 l = buffer.GetUpperBound(0);
64 for (i = buffer.GetLowerBound(0); i < l; i++)
66 buffer[i] = (byte)(this.Sample()*Byte.MaxValue);
70 public virtual double NextDouble ()
75 protected virtual double Sample ()
80 return S/(double)Int32.MaxValue;