/// <summary> /// Initializes a new instance of the <see cref="LinearFeedbackShiftRegister32"/> class. /// </summary> /// <param name="seed">The seed to initialise the sequence with</param> public LinearFeedbackShiftRegister32(UInt32 seed) { mostSignificantBits = new LinearFeedbackShiftRegister16((UInt16)seed); leastSignificantBits = new LinearFeedbackShiftRegister16((UInt16)(seed >> 16)); repeatThreshold = mostSignificantBits.NextRandom(); lsb = leastSignificantBits.NextRandom(); }
/// <summary> /// Initializes a new instance of the <see cref="LinearFeedbackShiftRegister32"/> class. /// </summary> /// <param name="seed">The seed to initialise the sequence with</param> public LinearFeedbackShiftRegister32(uint seed) { _mostSignificantBits = new LinearFeedbackShiftRegister16((ushort)(seed & ushort.MaxValue)); _leastSignificantBits = new LinearFeedbackShiftRegister16((ushort)((seed >> 16) & ushort.MaxValue)); _repeatThreshold = _mostSignificantBits.NextRandom(); _lsb = _leastSignificantBits.NextRandom(); }
/// <summary> /// Checks if this is implemented correctly /// </summary> public static void CorrectnessTest() { LinearFeedbackShiftRegister16 r = new LinearFeedbackShiftRegister16(); UInt16 first = r.NextRandom(); UInt16 value; int period = 0; do { value = r.NextRandom(); ++period; } while (value != first); if (period != PERIOD) { throw new Exception("Period is incorrect"); } }