/// <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."); }
/// <summary> /// Reseed the Unity Random 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) { #if UNITY_5_4_OR_NEWER UnityEngine.Random.InitState((int)bitGenerator.Next32()); #else UnityEngine.Random.seed = (int)bitGenerator.Next32(); #endif }
/// <summary> /// Reseed the Unity Random 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) { #if UNITY_5_4_OR_NEWER IBitGenerator currentState = new RandomStateGenerator(SaveState()); UnityEngine.Random.InitState((int)(currentState.Next32() ^ bitGenerator.Next32())); #else UnityEngine.Random.seed ^= (int)bitGenerator.Next32(); #endif }
/// <summary> /// Reseed the XorShift-Add 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) { int tryCount = 0; do { uint state0 = bitGenerator.Next32(); uint state1 = bitGenerator.Next32(); uint state2 = bitGenerator.Next32(); uint state3 = bitGenerator.Next32(); if (state0 != 0 || state1 != 0 || state2 != 0 || state3 != 0) { _state0 = state0; _state1 = state1; _state2 = state2; _state3 = state3; 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."); }
/// <summary> /// Reseed the .NET System.Random 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 MergeSeed(IBitGenerator bitGenerator) { _random = new System.Random((int)(Next32() ^ bitGenerator.Next32())); }