Evolution/Evolution/Utils/XorShiftRandomSource.cs
/// <summary>
/// Generates a random int over the range lowerBound to upperBound-1, and not including upperBound.
/// upperBound must be >= lowerBound. lowerBound may be negative.
/// </summary>
Generates a random int over the range lowerBound to upperBound-1, and not including upperBound.
upperBound must be >= lowerBound. lowerBound may be negative.
Generates a random int over the range lowerBound to upperBound - 1 and not including upperBound . upperBound must be > = lowerBound . lowerBound may be negative .
public int Next(int lowerBound, int upperBound)
        {
            if (lowerBound > upperBound)
            {
                throw new ArgumentOutOfRangeException("upperBound", upperBound, "upperBound must be >=lowerBound");
            }
            uint t = _x ^ (_x << 11);
            _x = _y; _y = _z; _z = _w;
            int range = upperBound - lowerBound;
            if (range >= 0)
            {
                return lowerBound + (int)((REAL_UNIT_UINT * (_w = (_w ^ (_w >> 19)) ^ (t ^ (t >> 8)))) * range);
            }
            return lowerBound + (int)((REAL_UNIT_UINT * (_w = (_w ^ (_w >> 19)) ^ (t ^ (t >> 8)))) * ((long)upperBound - (long)lowerBound));
        }
public int Next ( int lowerBound , int upperBound ) { if ( lowerBound > upperBound ) { throw new ArgumentOutOfRangeException ( " " , upperBound , " " ) ; } uint t = _x ^ ( _x << 11 ) ; _x = _y ; _y = _z ; _z = _w ; int range = upperBound - lowerBound ; if ( range >= 0 ) { return lowerBound + ( int ) ( ( REAL_UNIT_UINT * ( _w = ( _w ^ ( _w >> 19 ) ) ^ ( t ^ ( t >> 8 ) ) ) ) * range ) ; } return lowerBound + ( int ) ( ( REAL_UNIT_UINT * ( _w = ( _w ^ ( _w >> 19 ) ) ^ ( t ^ ( t >> 8 ) ) ) ) * ( ( long ) upperBound - ( long ) lowerBound ) ) ; }
Generates a random int over the range lowerBound to upperBound-1, and not including upperBound.
Generates a random int over the range lowerBound to upperBound - 1 and not including upperBound .
// Test if range will fit into an Int32. // When range is less than 0 then an overflow has occured and therefore we must resort to using long integer arithmetic (which is slower).
lowerBound
int
upperBound
int