using System; using System.Runtime.InteropServices; namespace System { /// Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet certain statistical requirements for randomness. /// 1 // Token: 0x020006A1 RID: 1697 [ComVisible(true)] [Serializable] public class Random { /// Initializes a new instance of the class, using a time-dependent default seed value. /// The seed value derived from the system clock is , which causes an overflow when its absolute value is calculated. // Token: 0x0600406C RID: 16492 RVA: 0x000DB984 File Offset: 0x000D9B84 public Random() : this(Environment.TickCount) { } /// Initializes a new instance of the class, using the specified seed value. /// A number used to calculate a starting value for the pseudo-random number sequence. If a negative number is specified, the absolute value of the number is used. /// /// is , which causes an overflow when its absolute value is calculated. // Token: 0x0600406D RID: 16493 RVA: 0x000DB994 File Offset: 0x000D9B94 public Random(int Seed) { int num = 161803398 - Math.Abs(Seed); this.SeedArray[55] = num; int num2 = 1; for (int i = 1; i < 55; i++) { int num3 = 21 * i % 55; this.SeedArray[num3] = num2; num2 = num - num2; if (num2 < 0) { num2 += int.MaxValue; } num = this.SeedArray[num3]; } for (int j = 1; j < 5; j++) { for (int k = 1; k < 56; k++) { this.SeedArray[k] -= this.SeedArray[1 + (k + 30) % 55]; if (this.SeedArray[k] < 0) { this.SeedArray[k] += int.MaxValue; } } } this.inext = 0; this.inextp = 31; } /// Returns a random number between 0.0 and 1.0. /// A double-precision floating point number greater than or equal to 0.0, and less than 1.0. // Token: 0x0600406E RID: 16494 RVA: 0x000DBA90 File Offset: 0x000D9C90 protected virtual double Sample() { if (++this.inext >= 56) { this.inext = 1; } if (++this.inextp >= 56) { this.inextp = 1; } int num = this.SeedArray[this.inext] - this.SeedArray[this.inextp]; if (num < 0) { num += int.MaxValue; } this.SeedArray[this.inext] = num; return (double)num * 4.656612875245797E-10; } /// Returns a nonnegative random number. /// A 32-bit signed integer greater than or equal to zero and less than . /// 1 // Token: 0x0600406F RID: 16495 RVA: 0x000DBB20 File Offset: 0x000D9D20 public virtual int Next() { return (int)(this.Sample() * 2147483647.0); } /// Returns a nonnegative random number less than the specified maximum. /// A 32-bit signed integer greater than or equal to zero, and less than ; that is, the range of return values ordinarily includes zero but not . However, if equals zero, is returned. /// The exclusive upper bound of the random number to be generated. must be greater than or equal to zero. /// /// is less than zero. /// 1 // Token: 0x06004070 RID: 16496 RVA: 0x000DBB34 File Offset: 0x000D9D34 public virtual int Next(int maxValue) { if (maxValue < 0) { throw new ArgumentOutOfRangeException(Locale.GetText("Max value is less than min value.")); } return (int)(this.Sample() * (double)maxValue); } /// Returns a random number within a specified range. /// A 32-bit signed integer greater than or equal to and less than ; that is, the range of return values includes but not . If equals , is returned. /// The inclusive lower bound of the random number returned. /// The exclusive upper bound of the random number returned. must be greater than or equal to . /// /// is greater than . /// 1 // Token: 0x06004071 RID: 16497 RVA: 0x000DBB58 File Offset: 0x000D9D58 public virtual int Next(int minValue, int maxValue) { if (minValue > maxValue) { throw new ArgumentOutOfRangeException(Locale.GetText("Min value is greater than max value.")); } uint num = (uint)(maxValue - minValue); if (num <= 1U) { return minValue; } return (int)((ulong)((uint)(this.Sample() * num)) + (ulong)((long)minValue)); } /// Fills the elements of a specified array of bytes with random numbers. /// An array of bytes to contain random numbers. /// /// is null. /// 1 // Token: 0x06004072 RID: 16498 RVA: 0x000DBB9C File Offset: 0x000D9D9C public virtual void NextBytes(byte[] buffer) { if (buffer == null) { throw new ArgumentNullException("buffer"); } for (int i = 0; i < buffer.Length; i++) { buffer[i] = (byte)(this.Sample() * 256.0); } } /// Returns a random number between 0.0 and 1.0. /// A double-precision floating point number greater than or equal to 0.0, and less than 1.0. /// 1 // Token: 0x06004073 RID: 16499 RVA: 0x000DBBE4 File Offset: 0x000D9DE4 public virtual double NextDouble() { return this.Sample(); } // Token: 0x040019A0 RID: 6560 private const int MBIG = 2147483647; // Token: 0x040019A1 RID: 6561 private const int MSEED = 161803398; // Token: 0x040019A2 RID: 6562 private const int MZ = 0; // Token: 0x040019A3 RID: 6563 private int inext; // Token: 0x040019A4 RID: 6564 private int inextp; // Token: 0x040019A5 RID: 6565 private int[] SeedArray = new int[56]; } }