Redzen.Numerics.XorShiftRandom.NextInt C# (CSharp) Method

NextInt() public method

Generates a random int over the range 0 to int.MaxValue, inclusive. This method differs from Next() only in that the range is 0 to int.MaxValue and not 0 to int.MaxValue-1. The slight difference in range means this method is slightly faster than Next() but is not functionally equivalent to System.Random.Next().
public NextInt ( ) : int
return int
        public int NextInt()
        {
            uint t = _x^(_x<<11);
            _x=_y; _y=_z; _z=_w;
            return (int)(0x7FFFFFFF&(_w=(_w^(_w>>19))^(t^(t>>8))));
        }

Usage Example

Example #1
0
        public void NextInt()
        {
            int sampleCount = 10000000;
            XorShiftRandom rng = new XorShiftRandom();
            double[] sampleArr = new double[sampleCount];

            for(int i=0; i<sampleCount; i++){
                sampleArr[i] = rng.NextInt();
            }

            UniformDistributionTest(sampleArr, 0.0, int.MaxValue + 1.0);
        }
All Usage Examples Of Redzen.Numerics.XorShiftRandom::NextInt