/// <summary> /// Restores the state of the number generator based on the specified state parameter /// </summary> /// <example> /// If you generated three random numbers and then called Save to store the state and /// followed that up by generating 10 more numbers before calling Restore with the previously saved RandomState /// the Restore method should return the generator back to the state when Save was first called. /// This means that if you went on to generate 10 more numbers they would be the same 10 numbers that were /// generated the first time after Save was called. /// </example> /// <param name="state">The state to restore to, usually obtained from calling the Save method</param> /// <exception cref="ArgumentNullException">Thrown on null RandomState</exception> public void Restore(RandomState state) { if (state == null) { throw new ArgumentNullException("state", "RandomState cannot be null"); } _series = new Queue <int>(); foreach (int i in state.Seed) { _series.Enqueue(i); } _numberGenerated = state.NumberGenerated; }
/// <summary> /// Restores the state of the pseudo-random number generator based on the specified state parameter /// </summary> /// <example> /// If you generated three random numbers and then called Save to store the state and /// followed that up by generating 10 more numbers before calling Restore with the previously saved RandomState /// the Restore method should return the generator back to the state when Save was first called. /// This means that if you went on to generate 10 more numbers they would be the same 10 numbers that were /// generated the first time after Save was called. /// </example> /// <param name="state">The state to restore to, usually obtained from calling the Save method</param> /// <exception cref="ArgumentNullException">RandomState cannot be null</exception> public void Restore(RandomState state) { if (state == null) { throw new ArgumentNullException("state", "RandomState cannot be null"); } _seed = state.Seed[0]; _random = new System.Random(_seed); for (long i = 0; i < state.NumberGenerated; i++) { _random.Next(); } }
/// <summary> /// Restores the state of the pseudo-random number generator based on the specified state parameter /// </summary> /// <example> /// If you generated three random numbers and then called Save to store the state and /// followed that up by generating 10 more numbers before calling Restore with the previously saved RandomState /// the Restore method should return the generator back to the state when Save was first called. /// This means that if you went on to generate 10 more numbers they would be the same 10 numbers that were /// generated the first time after Save was called. /// </example> /// <param name="state">The state to restore to, usually obtained from calling the Save method</param> /// <exception cref="ArgumentNullException">Thrown on null RandomState</exception> public void Restore(RandomState state) { if (state == null) { throw new ArgumentNullException("state", "RandomState cannot be null"); } _seed = state.Seed[0]; _random = new System.Random(_seed); _numberGenerated = default(long); _nextGaussian = default(double); _uselast = true; for (long i = 0; i < state.NumberGenerated; i++) { Next(1); } }