Lidgren.Network.NetRandom.NextBool C# (CSharp) Method

NextBool() public method

Generates a single random bit. This method's performance is improved by generating 32 bits in one operation and storing them ready for future calls.
public NextBool ( ) : bool
return bool
        public bool NextBool()
        {
            if (bitMask == 1)
            {
                // Generate 32 more bits.
                uint t = (x ^ (x << 11));
                x = y; y = z; z = w;
                bitBuffer = w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));

                // Reset the bitMask that tells us which bit to read next.
                bitMask = 0x80000000;
                return (bitBuffer & bitMask) == 0;
            }

            return (bitBuffer & (bitMask >>= 1)) == 0;
        }