/// <summary> /// Creates a /// Mersenne Twister 19937 generator having the /// specified seed. /// </summary> /// <param name="seed">The seed of the generator.</param> /// <returns>The MT 19937 generator having the specified seed.</returns> /// <remarks> /// <para> /// The MT 19937 generator has a period length equal /// to <latex mode='inline'>2^19937</latex>. /// </para> /// </remarks> /// <seealso href="https://en.wikipedia.org/wiki/Mersenne_Twister"/> public static RandomNumberGenerator CreateMT19937(int seed) { var descriptor = VslSafeStreamStateDescriptor.Create( SafeNativeMethods.VSL.BRNG.VSL_BRNG_MT19937, seed); return(new RandomNumberGenerator(descriptor)); }
/// <summary> /// Creates the next pseudo random generator in the sequence of /// Mersenne Twister 2203 generators having the /// specified seed. /// </summary> /// <param name="seed">The seed of the generator.</param> /// <returns>The next MT 2203 generator having the specified seed.</returns> /// <remarks> /// <para> /// There are <c>6024</c> MT2203 pseudo random number generators. /// The MT 2203 generators guarantee mutual /// independence of the corresponding random number sequences. /// Every MT 2203 generator has a period length equal /// to <latex mode='inline'>2^2203</latex>. /// </para> /// <para> /// Method <see cref="CreateNextMT2203(int)"/> increments the iterator /// to the next position in the sequence, or to the first position beyond the /// end of sequence if the sequence has been completely traversed. /// </para> /// </remarks> /// <seealso href="https://en.wikipedia.org/wiki/Mersenne_Twister"/> public static RandomNumberGenerator CreateNextMT2203(int seed) { Interlocked.CompareExchange(ref mersenneTwister2203, -1, 6023); int currentGenerator = Interlocked.Increment(ref mersenneTwister2203); var descriptor = VslSafeStreamStateDescriptor.Create( SafeNativeMethods.VSL.BRNG.VSL_BRNG_MT2203 + currentGenerator, seed); return(new RandomNumberGenerator(descriptor)); }
private RandomNumberGenerator(VslSafeStreamStateDescriptor descriptor) { this.descriptor = descriptor; }