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

NextFloat() public method

Generates a random float. Values returned are over the range [0, 1). That is, inclusive of 0.0 and exclusive of 1.0.
public NextFloat ( ) : float
return float
        public float NextFloat()
        {
            uint t = _x^(_x<<11);
            _x=_y; _y=_z; _z=_w;

            // N.B. Here we're using the full 32 bits of randomness, whereas System.Random uses 31 bits.
            return REAL_UNIT_UINT_F * (_w=(_w^(_w>>19))^(t^(t>>8)));
        }

Usage Example

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

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

            UniformDistributionTest(sampleArr, 0.0, 1.0);
        }