5 // Bob Smith (bob@thestuff.net)
7 // (C) 2001 Bob Smith. http://www.thestuff.net
17 private const int A = 16807;
18 private const int M = 2147483647;
19 private const int Q = 127773;
20 private const int R = 2836;
21 public const byte MaxValue = 0xFF;
22 public const byte MinValue = 0x00;
25 S = (int)DateTime.Now;
27 public Random(int Seed)
31 public virtual int Next()
33 return (int)(Random.Sample()*Random.MaxValue);
35 public virtual int Next(int maxValue)
37 if (maxValue < Random.MinValue)
38 throw new ArgumentOutOfRangeException("Max value is less then min value.");
39 else if (maxValue == Random.MinValue)
40 return Random.MinValue;
41 return (int)(Random.Sample()*maxValue);
43 public virtual int Next(int minValue, int maxValue)
45 if (minValue > maxValue)
46 throw new ArgumentOutOfRangeException("Min value is greater then max value.");
47 else if (minValue == maxValue)
49 return (int)(Random.Sample()*maxValue)+minValue;
51 public virtual void NextBytes(byte[] buffer)
55 throw ArgumentNullException();
56 l = buffer.GetUpperBound(0);
57 for (i = buffer.GetLowerBound(0); i < l; i++)
59 buffer[i] = (byte)(Random.Sample()*Random.MaxValue);
62 public virtual double NextDouble()
64 return Random.Sample();
66 protected virtual double Sample(){
69 return S/(double)Int32.MaxValue;