Changeset 1575
- Timestamp:
- 1/18/2010 7:48:08 AM (3 years ago)
- File:
-
- 1 edited
-
branches/eraser6/CodeReview/Eraser.Manager/PRNG.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/CodeReview/Eraser.Manager/PRNG.cs
r1360 r1575 115 115 /// <returns>A 32-bit signed integer greater than or equal to zero and less 116 116 /// than System.Int32.MaxValue.</returns> 117 public unsafe int Next() 118 { 119 //Declare a return variable 120 int result; 121 int* fResult = &result; 122 117 public int Next() 118 { 123 119 //Get the random-valued bytes to fill the int. 124 120 byte[] rand = new byte[sizeof(int)]; 125 121 NextBytes(rand); 126 122 127 //Copy the random buffer into the int. 128 fixed (byte* fRand = rand) 129 { 130 byte* pResult = (byte*)fResult; 131 byte* pRand = fRand; 132 for (int i = 0; i != sizeof(int); ++i) 133 *pResult++ = *pRand++; 134 } 135 136 return Math.Abs(result); 123 //Then return the integral representation of the buffer. 124 return Math.Abs(BitConverter.ToInt32(rand, 0)); 137 125 } 138 126
Note: See TracChangeset
for help on using the changeset viewer.
