Changeset 1575


Ignore:
Timestamp:
1/18/2010 7:48:08 AM (4 years ago)
Author:
lowjoel
Message:

Remove an unnecessary unsafe function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/CodeReview/Eraser.Manager/PRNG.cs

    r1360 r1575  
    115115        /// <returns>A 32-bit signed integer greater than or equal to zero and less 
    116116        /// 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        { 
    123119            //Get the random-valued bytes to fill the int. 
    124120            byte[] rand = new byte[sizeof(int)]; 
    125121            NextBytes(rand); 
    126122 
    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)); 
    137125        } 
    138126 
Note: See TracChangeset for help on using the changeset viewer.