/// <summary>
        /// Reseed the XorShift128+ engine with a combination of its current state and the supplied bit generator.
        /// </summary>
        /// <param name="bitGenerator">A supplier of bits used, in conjuction with the current state, to directly determine the new state of the random engine.</param>
        /// <seealso cref="IRandom"/>
        /// <seealso cref="RandomStateGenerator"/>
        public override void MergeSeed(IBitGenerator bitGenerator)
        {
            int tryCount = 0;

            do
            {
#if MAKEITRANDOM_OPTIMIZE_FOR_32BIT
                uint state0 = _state0 ^ bitGenerator.Next32();
                uint state1 = _state1 ^ bitGenerator.Next32();
                uint state2 = _state2 ^ bitGenerator.Next32();
                uint state3 = _state3 ^ bitGenerator.Next32();
                if (state0 != 0 || state1 != 0 || state2 != 0 || state3 != 0)
                {
                    _state0 = state0;
                    _state1 = state1;
                    _state2 = state2;
                    _state3 = state3;
                    return;
                }
#else
                ulong state0 = _state0 ^ bitGenerator.Next64();
                ulong state1 = _state1 ^ bitGenerator.Next64();
                if (state0 != 0 || state1 != 0)
                {
                    _state0 = state0;
                    _state1 = state1;
                    return;
                }
#endif
            } while (++tryCount < 4);

            throw new System.ArgumentException("The provided bit generator was unable to generate a non-zero state, which is required by this random engine.");
        }
Exemple #2
0
        /// <summary>
        /// Reseed the XoroShiro128+ engine with a combination of its current state and the supplied bit generator.
        /// </summary>
        /// <param name="bitGenerator">A supplier of bits used, in conjuction with the current state, to directly determine the new state of the random engine.</param>
        /// <seealso cref="IRandom"/>
        /// <seealso cref="RandomStateGenerator"/>
        public override void MergeSeed(IBitGenerator bitGenerator)
        {
            int tryCount = 0;

            do
            {
                ulong state0 = _state0 ^ bitGenerator.Next64();
                ulong state1 = _state1 ^ bitGenerator.Next64();
                if (state0 != 0 && state1 != 0)
                {
                    _state0 = state0;
                    _state1 = state1;
                    return;
                }
            } while (++tryCount < 4);

            throw new System.ArgumentException("The provided bit generator was unable to generate a non-zero state, which is required by this random engine.");
        }
Exemple #3
0
        /// <summary>
        /// Reseed the XorShift1024* engine with a combination of its current state and the supplied bit generator.
        /// </summary>
        /// <param name="bitGenerator">A supplier of bits used, in conjuction with the current state, to directly determine the new state of the random engine.</param>
        /// <seealso cref="IRandom"/>
        /// <seealso cref="RandomStateGenerator"/>
        public override void MergeSeed(IBitGenerator bitGenerator)
        {
            int tryCount = 0;

            do
            {
                ulong[] state     = new ulong[16];
                bool    allZeroes = true;
                for (int i = 0; i < 16; ++i)
                {
                    state[i]  = _state[i] ^ bitGenerator.Next64();
                    allZeroes = allZeroes && state[i] == 0;
                }
                if (!allZeroes)
                {
                    _state = state;
                    return;
                }
            } while (++tryCount < 4);

            throw new System.ArgumentException("The provided bit generator was unable to generate a non-zero state, which is required by this random engine.");
        }
Exemple #4
0
 /// <summary>
 /// Reseed the SplitMix64 engine with a combination of its current state and the supplied bit generator.
 /// </summary>
 /// <param name="bitGenerator">A supplier of bits used, in conjuction with the current state, to directly determine the new state of the random engine.</param>
 /// <seealso cref="IRandom"/>
 /// <seealso cref="RandomStateGenerator"/>
 public override void MergeSeed(IBitGenerator bitGenerator)
 {
     _state ^= bitGenerator.Next64();
 }
Exemple #5
0
 /// <summary>
 /// Reseed the SplitMix64 engine with the supplied bit generator.
 /// </summary>
 /// <param name="bitGenerator">A supplier of bits used to directly determine the new state of the random engine.</param>
 /// <seealso cref="IRandom"/>
 /// <seealso cref="RandomStateGenerator"/>
 public override void Seed(IBitGenerator bitGenerator)
 {
     _state = bitGenerator.Next64();
 }