Changeset 563
- Timestamp:
- 11/14/2008 9:05:23 AM (5 years ago)
- File:
-
- 1 edited
-
branches/eraser6/Manager/PRNG.cs (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Manager/PRNG.cs
r549 r563 40 40 /// random data erase passes. 41 41 /// </summary> 42 public abstract class PRNG : Random42 public abstract class PRNG 43 43 { 44 44 public override string ToString() … … 74 74 75 75 #region Random members 76 public override int Next(int maxValue) 76 /// <summary> 77 /// Returns a nonnegative random number less than the specified maximum. 78 /// </summary> 79 /// <param name="maxValue">The exclusive upper bound of the random number 80 /// to be generated. maxValue must be greater than or equal to zero.</param> 81 /// <returns>A 32-bit signed integer greater than or equal to zero, and 82 /// less than maxValue; that is, the range of return values ordinarily 83 /// includes zero but not maxValue. However, if maxValue equals zero, 84 /// maxValue is returned.</returns> 85 public int Next(int maxValue) 77 86 { 78 87 if (maxValue == 0) … … 81 90 } 82 91 83 public override int Next(int minValue, int maxValue) 92 /// <summary> 93 /// Returns a random number within a specified range. 94 /// </summary> 95 /// <param name="minValue">The inclusive lower bound of the random number 96 /// returned.</param> 97 /// <param name="maxValue">The exclusive upper bound of the random number 98 /// returned. maxValue must be greater than or equal to minValue.</param> 99 /// <returns>A 32-bit signed integer greater than or equal to minValue and 100 /// less than maxValue; that is, the range of return values includes minValue 101 /// but not maxValue. If minValue equals maxValue, minValue is returned.</returns> 102 public int Next(int minValue, int maxValue) 84 103 { 85 104 if (minValue > maxValue) … … 90 109 } 91 110 92 public unsafe override int Next() 111 /// <summary> 112 /// Returns a nonnegative random number. 113 /// </summary> 114 /// <returns>A 32-bit signed integer greater than or equal to zero and less 115 /// than System.Int32.MaxValue.</returns> 116 public unsafe int Next() 93 117 { 94 118 //Declare a return variable … … 112 136 } 113 137 114 protected unsafe override double Sample() 115 { 116 //Declare a return variable 117 double result; 118 double* fResult = &result; 119 120 //Get the random-valued bytes to fill the int. 121 byte[] rand = new byte[sizeof(double)]; 122 NextBytes(rand); 123 124 //Copy the random buffer into the int. 125 fixed (byte* fRand = rand) 126 { 127 byte* pResult = (byte*)fResult; 128 byte* pRand = fRand; 129 for (int i = 0; i != sizeof(double); ++i) 130 *pResult++ = *pRand++; 131 } 132 133 return result; 134 } 135 136 public abstract override void NextBytes(byte[] buffer); 138 /// <summary> 139 /// Fills the elements of a specified array of bytes with random numbers. 140 /// </summary> 141 /// <param name="buffer">An array of bytes to contain random numbers.</param> 142 public abstract void NextBytes(byte[] buffer); 137 143 #endregion 138 144 }
Note: See TracChangeset
for help on using the changeset viewer.
