5 // Bob Smith (bob@thestuff.net)
7 // (C) 2001 Bob Smith. http://www.thestuff.net
11 using System.Globalization;
18 private const int A = 16807;
19 private const int M = 2147483647;
20 private const int Q = 127773;
21 private const int R = 2836;
25 S = (int)(DateTime.Now.Ticks);
28 public Random(int Seed)
33 public virtual int Next()
35 return (int)(this.Sample()*Int32.MaxValue);
38 public virtual int Next(int maxValue)
41 throw new ArgumentOutOfRangeException(Locale.GetText (
42 "Max value is less then min value."));
43 else if (maxValue == 0)
45 return (int)(this.Sample()*maxValue);
48 public virtual int Next(int minValue, int maxValue)
50 if (minValue > maxValue)
51 throw new ArgumentOutOfRangeException(Locale.GetText (
52 "Min value is greater then max value."));
53 else if (minValue == maxValue)
55 return (int)(this.Sample()*maxValue)+minValue;
57 public virtual void NextBytes(byte[] buffer)
61 throw new ArgumentNullException();
62 l = buffer.GetUpperBound(0);
63 for (i = buffer.GetLowerBound(0); i < l; i++)
65 buffer[i] = (byte)(this.Sample()*Byte.MaxValue);
69 public virtual double NextDouble ()
74 protected virtual double Sample ()
79 return S/(double)Int32.MaxValue;