diff --git a/src/FSharp/Random.fs b/src/FSharp/Random.fs index 5f375624..ebd64895 100644 --- a/src/FSharp/Random.fs +++ b/src/FSharp/Random.fs @@ -33,6 +33,9 @@ namespace MathNet.Numerics.Random [] module Random = + /// Returns the default mersenne twister, thread-safe and also thread-locally shared + let shared = MersenneTwister.Default :> System.Random + /// Creates a default .Net system pRNG with a custom seed based on uinque GUIDs let system () = new System.Random(RandomSeed.Guid()) let systemSeed seed = new System.Random(seed) diff --git a/src/Numerics/Distributions/Bernoulli.cs b/src/Numerics/Distributions/Bernoulli.cs index 2ca62981..30fbd82c 100644 --- a/src/Numerics/Distributions/Bernoulli.cs +++ b/src/Numerics/Distributions/Bernoulli.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -58,7 +59,7 @@ namespace MathNet.Numerics.Distributions /// If the Bernoulli parameter is not in the range [0,1]. public Bernoulli(double p) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(p); } @@ -70,7 +71,7 @@ namespace MathNet.Numerics.Distributions /// If the Bernoulli parameter is not in the range [0,1]. public Bernoulli(double p, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(p); } @@ -123,7 +124,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Beta.cs b/src/Numerics/Distributions/Beta.cs index 4f060cee..8e428b60 100644 --- a/src/Numerics/Distributions/Beta.cs +++ b/src/Numerics/Distributions/Beta.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -65,7 +66,7 @@ namespace MathNet.Numerics.Distributions /// The β shape parameter of the Beta distribution. Range: β ≥ 0. public Beta(double a, double b) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(a, b); } @@ -77,7 +78,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Beta(double a, double b, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(a, b); } @@ -131,7 +132,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Binomial.cs b/src/Numerics/Distributions/Binomial.cs index 6d04e3c0..1f3c63f1 100644 --- a/src/Numerics/Distributions/Binomial.cs +++ b/src/Numerics/Distributions/Binomial.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -61,7 +62,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Binomial(double p, int n) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(p, n); } @@ -75,7 +76,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Binomial(double p, int n, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(p, n); } @@ -141,7 +142,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Categorical.cs b/src/Numerics/Distributions/Categorical.cs index 82f29932..ca98c341 100644 --- a/src/Numerics/Distributions/Categorical.cs +++ b/src/Numerics/Distributions/Categorical.cs @@ -32,6 +32,7 @@ using System; using System.Collections.Generic; using System.Linq; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; using MathNet.Numerics.Statistics; namespace MathNet.Numerics.Distributions @@ -65,7 +66,7 @@ namespace MathNet.Numerics.Distributions /// If any of the probabilities are negative or do not sum to one. public Categorical(double[] probabilityMass) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(probabilityMass); } @@ -78,7 +79,7 @@ namespace MathNet.Numerics.Distributions /// If any of the probabilities are negative or do not sum to one. public Categorical(double[] probabilityMass, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(probabilityMass); } @@ -104,7 +105,7 @@ namespace MathNet.Numerics.Distributions p[i] = histogram[i].Count; } - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(p); } @@ -207,7 +208,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Cauchy.cs b/src/Numerics/Distributions/Cauchy.cs index cda19f58..f7dde704 100644 --- a/src/Numerics/Distributions/Cauchy.cs +++ b/src/Numerics/Distributions/Cauchy.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -65,7 +66,7 @@ namespace MathNet.Numerics.Distributions /// The scale (γ) of the distribution. Range: γ > 0. public Cauchy(double location, double scale) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(location, scale); } @@ -77,7 +78,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Cauchy(double location, double scale, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(location, scale); } @@ -131,7 +132,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Chi.cs b/src/Numerics/Distributions/Chi.cs index d6fe0a31..a62ea32d 100644 --- a/src/Numerics/Distributions/Chi.cs +++ b/src/Numerics/Distributions/Chi.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -58,7 +59,7 @@ namespace MathNet.Numerics.Distributions /// The degrees of freedom (k) of the distribution. Range: k > 0. public Chi(double freedom) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(freedom); } @@ -69,7 +70,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Chi(double freedom, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(freedom); } @@ -112,7 +113,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/ChiSquared.cs b/src/Numerics/Distributions/ChiSquared.cs index 8a85050d..be1969c1 100644 --- a/src/Numerics/Distributions/ChiSquared.cs +++ b/src/Numerics/Distributions/ChiSquared.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -56,7 +57,7 @@ namespace MathNet.Numerics.Distributions /// The degrees of freedom (k) of the distribution. Range: k > 0. public ChiSquared(double freedom) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(freedom); } @@ -67,7 +68,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public ChiSquared(double freedom, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(freedom); } @@ -110,7 +111,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/ContinuousUniform.cs b/src/Numerics/Distributions/ContinuousUniform.cs index b62b8ff5..7b13cec8 100644 --- a/src/Numerics/Distributions/ContinuousUniform.cs +++ b/src/Numerics/Distributions/ContinuousUniform.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -66,7 +67,7 @@ namespace MathNet.Numerics.Distributions /// If the upper bound is smaller than the lower bound. public ContinuousUniform(double lower, double upper) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(lower, upper); } @@ -79,7 +80,7 @@ namespace MathNet.Numerics.Distributions /// If the upper bound is smaller than the lower bound. public ContinuousUniform(double lower, double upper, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(lower, upper); } @@ -133,7 +134,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/ConwayMaxwellPoisson.cs b/src/Numerics/Distributions/ConwayMaxwellPoisson.cs index cd932321..2568ec90 100644 --- a/src/Numerics/Distributions/ConwayMaxwellPoisson.cs +++ b/src/Numerics/Distributions/ConwayMaxwellPoisson.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -86,7 +87,7 @@ namespace MathNet.Numerics.Distributions /// The rate of decay (ν) parameter. Range: ν ≥ 0. public ConwayMaxwellPoisson(double lambda, double nu) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(lambda, nu); } @@ -98,7 +99,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public ConwayMaxwellPoisson(double lambda, double nu, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(lambda, nu); } @@ -163,7 +164,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Dirichlet.cs b/src/Numerics/Distributions/Dirichlet.cs index d67da14a..f3eb9810 100644 --- a/src/Numerics/Distributions/Dirichlet.cs +++ b/src/Numerics/Distributions/Dirichlet.cs @@ -31,6 +31,7 @@ using System; using System.Linq; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -56,7 +57,7 @@ namespace MathNet.Numerics.Distributions /// An array with the Dirichlet parameters. public Dirichlet(double[] alpha) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(alpha); } @@ -68,7 +69,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Dirichlet(double[] alpha, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(alpha); } @@ -86,7 +87,7 @@ namespace MathNet.Numerics.Distributions parm[i] = alpha; } - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(parm); } @@ -105,7 +106,7 @@ namespace MathNet.Numerics.Distributions parm[i] = alpha; } - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(parm); } @@ -179,7 +180,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/DiscreteUniform.cs b/src/Numerics/Distributions/DiscreteUniform.cs index 623017a4..3a38c891 100644 --- a/src/Numerics/Distributions/DiscreteUniform.cs +++ b/src/Numerics/Distributions/DiscreteUniform.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -59,7 +60,7 @@ namespace MathNet.Numerics.Distributions /// Upper bound. Range: lower ≤ upper. public DiscreteUniform(int lower, int upper) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(lower, upper); } @@ -71,7 +72,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public DiscreteUniform(int lower, int upper, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(lower, upper); } @@ -138,7 +139,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Erlang.cs b/src/Numerics/Distributions/Erlang.cs index 5c729119..d7c48104 100644 --- a/src/Numerics/Distributions/Erlang.cs +++ b/src/Numerics/Distributions/Erlang.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -59,7 +60,7 @@ namespace MathNet.Numerics.Distributions /// The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0. public Erlang(int shape, double rate) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(shape, rate); } @@ -71,7 +72,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Erlang(int shape, double rate, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(shape, rate); } @@ -166,7 +167,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Exponential.cs b/src/Numerics/Distributions/Exponential.cs index 2779e605..f78a2e74 100644 --- a/src/Numerics/Distributions/Exponential.cs +++ b/src/Numerics/Distributions/Exponential.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -56,7 +57,7 @@ namespace MathNet.Numerics.Distributions /// The rate (λ) parameter of the distribution. Range: λ ≥ 0. public Exponential(double rate) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(rate); } @@ -67,7 +68,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Exponential(double rate, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(rate); } @@ -110,7 +111,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/FisherSnedecor.cs b/src/Numerics/Distributions/FisherSnedecor.cs index efd9b2c0..928d9621 100644 --- a/src/Numerics/Distributions/FisherSnedecor.cs +++ b/src/Numerics/Distributions/FisherSnedecor.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -58,7 +59,7 @@ namespace MathNet.Numerics.Distributions /// The second degree of freedom (d2) of the distribution. Range: d2 > 0. public FisherSnedecor(double d1, double d2) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(d1, d2); } @@ -70,7 +71,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public FisherSnedecor(double d1, double d2, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(d1, d2); } @@ -124,7 +125,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Gamma.cs b/src/Numerics/Distributions/Gamma.cs index b9c3a774..85926ccf 100644 --- a/src/Numerics/Distributions/Gamma.cs +++ b/src/Numerics/Distributions/Gamma.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -66,7 +67,7 @@ namespace MathNet.Numerics.Distributions /// The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0. public Gamma(double shape, double rate) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(shape, rate); } @@ -78,7 +79,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Gamma(double shape, double rate, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(shape, rate); } @@ -173,7 +174,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Geometric.cs b/src/Numerics/Distributions/Geometric.cs index 5a546734..d5c5181d 100644 --- a/src/Numerics/Distributions/Geometric.cs +++ b/src/Numerics/Distributions/Geometric.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -57,7 +58,7 @@ namespace MathNet.Numerics.Distributions /// The probability (p) of generating one. Range: 0 ≤ p ≤ 1. public Geometric(double p) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(p); } @@ -68,7 +69,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Geometric(double p, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(p); } @@ -121,7 +122,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Hypergeometric.cs b/src/Numerics/Distributions/Hypergeometric.cs index b29f6725..e54c44f5 100644 --- a/src/Numerics/Distributions/Hypergeometric.cs +++ b/src/Numerics/Distributions/Hypergeometric.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -63,7 +64,7 @@ namespace MathNet.Numerics.Distributions /// The number of draws without replacement (n). public Hypergeometric(int population, int success, int draws) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(population, success, draws); } @@ -76,7 +77,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Hypergeometric(int population, int success, int draws, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(population, success, draws); } @@ -128,7 +129,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/InverseGamma.cs b/src/Numerics/Distributions/InverseGamma.cs index 90a227cd..d80c5c58 100644 --- a/src/Numerics/Distributions/InverseGamma.cs +++ b/src/Numerics/Distributions/InverseGamma.cs @@ -32,6 +32,7 @@ using System; using System.Collections.Generic; using System.Linq; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -60,7 +61,7 @@ namespace MathNet.Numerics.Distributions /// The scale (β) of the distribution. Range: β > 0. public InverseGamma(double shape, double scale) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(shape, scale); } @@ -72,7 +73,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public InverseGamma(double shape, double scale, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(shape, scale); } @@ -126,7 +127,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/InverseWishart.cs b/src/Numerics/Distributions/InverseWishart.cs index 6afbeb4a..03486e96 100644 --- a/src/Numerics/Distributions/InverseWishart.cs +++ b/src/Numerics/Distributions/InverseWishart.cs @@ -32,6 +32,7 @@ using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Factorization; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -65,7 +66,7 @@ namespace MathNet.Numerics.Distributions /// The scale matrix (Ψ) for the inverse Wishart distribution. public InverseWishart(double degreesOfFreedom, Matrix scale) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(degreesOfFreedom, scale); } @@ -77,7 +78,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public InverseWishart(double degreesOfFreedom, Matrix scale, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(degreesOfFreedom, scale); } @@ -156,7 +157,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Laplace.cs b/src/Numerics/Distributions/Laplace.cs index 5688bb19..79d26af1 100644 --- a/src/Numerics/Distributions/Laplace.cs +++ b/src/Numerics/Distributions/Laplace.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -69,7 +70,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Laplace(double location, double scale) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(location, scale); } @@ -82,7 +83,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Laplace(double location, double scale, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(location, scale); } @@ -136,7 +137,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/LogNormal.cs b/src/Numerics/Distributions/LogNormal.cs index 4f7f9f3c..891881a6 100644 --- a/src/Numerics/Distributions/LogNormal.cs +++ b/src/Numerics/Distributions/LogNormal.cs @@ -32,6 +32,7 @@ using System; using System.Collections.Generic; using System.Linq; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; using MathNet.Numerics.Statistics; namespace MathNet.Numerics.Distributions @@ -62,7 +63,7 @@ namespace MathNet.Numerics.Distributions /// The shape (σ) of the logarithm of the distribution. Range: σ ≥ 0. public LogNormal(double mu, double sigma) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(mu, sigma); } @@ -76,7 +77,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public LogNormal(double mu, double sigma, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(mu, sigma); } @@ -168,7 +169,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/MatrixNormal.cs b/src/Numerics/Distributions/MatrixNormal.cs index bedd6b17..71d2f94b 100644 --- a/src/Numerics/Distributions/MatrixNormal.cs +++ b/src/Numerics/Distributions/MatrixNormal.cs @@ -32,6 +32,7 @@ using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -74,7 +75,7 @@ namespace MathNet.Numerics.Distributions /// If the dimensions of the mean and two covariance matrices don't match. public MatrixNormal(Matrix m, Matrix v, Matrix k) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(m, v, k); } @@ -88,7 +89,7 @@ namespace MathNet.Numerics.Distributions /// If the dimensions of the mean and two covariance matrices don't match. public MatrixNormal(Matrix m, Matrix v, Matrix k, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(m, v, k); } @@ -198,7 +199,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Multinomial.cs b/src/Numerics/Distributions/Multinomial.cs index 7fb992e1..6a5b92ea 100644 --- a/src/Numerics/Distributions/Multinomial.cs +++ b/src/Numerics/Distributions/Multinomial.cs @@ -34,6 +34,7 @@ using System.Linq; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; using MathNet.Numerics.Statistics; namespace MathNet.Numerics.Distributions @@ -74,7 +75,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Multinomial(double[] p, int n) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(p, n); } @@ -89,7 +90,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Multinomial(double[] p, int n, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(p, n); } @@ -118,7 +119,7 @@ namespace MathNet.Numerics.Distributions } SetParameters(p, n); - RandomSource = new System.Random(Random.RandomSeed.Guid()); + RandomSource = MersenneTwister.Default; } /// @@ -201,7 +202,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/NegativeBinomial.cs b/src/Numerics/Distributions/NegativeBinomial.cs index 8ca52d43..ad93ba63 100644 --- a/src/Numerics/Distributions/NegativeBinomial.cs +++ b/src/Numerics/Distributions/NegativeBinomial.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -60,7 +61,7 @@ namespace MathNet.Numerics.Distributions /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. public NegativeBinomial(double r, double p) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(r, p); } @@ -72,7 +73,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public NegativeBinomial(double r, double p, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(r, p); } @@ -139,7 +140,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// /// Gets the mean of the distribution. diff --git a/src/Numerics/Distributions/Normal.cs b/src/Numerics/Distributions/Normal.cs index ef645a60..30882749 100644 --- a/src/Numerics/Distributions/Normal.cs +++ b/src/Numerics/Distributions/Normal.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; using MathNet.Numerics.Statistics; namespace MathNet.Numerics.Distributions @@ -81,7 +82,7 @@ namespace MathNet.Numerics.Distributions /// The standard deviation (σ) of the normal distribution. Range: σ ≥ 0. public Normal(double mean, double stddev) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(mean, stddev); } @@ -94,7 +95,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Normal(double mean, double stddev, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(mean, stddev); } @@ -224,7 +225,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/NormalGamma.cs b/src/Numerics/Distributions/NormalGamma.cs index 9b1c27b6..c5befeab 100644 --- a/src/Numerics/Distributions/NormalGamma.cs +++ b/src/Numerics/Distributions/NormalGamma.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -118,7 +119,7 @@ namespace MathNet.Numerics.Distributions /// The inverse scale of the precision. public NormalGamma(double meanLocation, double meanScale, double precisionShape, double precisionInverseScale) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(meanLocation, meanScale, precisionShape, precisionInverseScale); } @@ -132,7 +133,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public NormalGamma(double meanLocation, double meanScale, double precisionShape, double precisionInverseScale, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(meanLocation, meanScale, precisionShape, precisionInverseScale); } @@ -222,7 +223,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Pareto.cs b/src/Numerics/Distributions/Pareto.cs index 5092475c..9d395356 100644 --- a/src/Numerics/Distributions/Pareto.cs +++ b/src/Numerics/Distributions/Pareto.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -61,7 +62,7 @@ namespace MathNet.Numerics.Distributions /// If or are negative. public Pareto(double scale, double shape) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(scale, shape); } @@ -74,7 +75,7 @@ namespace MathNet.Numerics.Distributions /// If or are negative. public Pareto(double scale, double shape, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(scale, shape); } @@ -128,7 +129,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Poisson.cs b/src/Numerics/Distributions/Poisson.cs index 1e5cd05b..bfbf275a 100644 --- a/src/Numerics/Distributions/Poisson.cs +++ b/src/Numerics/Distributions/Poisson.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -55,7 +56,7 @@ namespace MathNet.Numerics.Distributions /// If is equal or less then 0.0. public Poisson(double lambda) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(lambda); } @@ -67,7 +68,7 @@ namespace MathNet.Numerics.Distributions /// If is equal or less then 0.0. public Poisson(double lambda, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(lambda); } @@ -122,7 +123,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Rayleigh.cs b/src/Numerics/Distributions/Rayleigh.cs index 77087628..cc73f680 100644 --- a/src/Numerics/Distributions/Rayleigh.cs +++ b/src/Numerics/Distributions/Rayleigh.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -60,7 +61,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Rayleigh(double scale) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(scale); } @@ -72,7 +73,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Rayleigh(double scale, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(scale); } @@ -115,7 +116,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Stable.cs b/src/Numerics/Distributions/Stable.cs index 816ec63b..c4897cd1 100644 --- a/src/Numerics/Distributions/Stable.cs +++ b/src/Numerics/Distributions/Stable.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -65,7 +66,7 @@ namespace MathNet.Numerics.Distributions /// The location (μ) of the distribution. public Stable(double alpha, double beta, double scale, double location) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(alpha, beta, scale, location); } @@ -79,7 +80,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Stable(double alpha, double beta, double scale, double location, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(alpha, beta, scale, location); } @@ -168,7 +169,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/StudentT.cs b/src/Numerics/Distributions/StudentT.cs index 22433370..92bb1210 100644 --- a/src/Numerics/Distributions/StudentT.cs +++ b/src/Numerics/Distributions/StudentT.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -83,7 +84,7 @@ namespace MathNet.Numerics.Distributions /// The degrees of freedom (ν) for the distribution. Range: ν > 0. public StudentT(double location, double scale, double freedom) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(location, scale, freedom); } @@ -98,7 +99,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public StudentT(double location, double scale, double freedom, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(location, scale, freedom); } @@ -175,7 +176,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Weibull.cs b/src/Numerics/Distributions/Weibull.cs index 91578fe0..8d282d85 100644 --- a/src/Numerics/Distributions/Weibull.cs +++ b/src/Numerics/Distributions/Weibull.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -69,7 +70,7 @@ namespace MathNet.Numerics.Distributions /// The scale (λ) of the Weibull distribution. Range: λ > 0. public Weibull(double shape, double scale) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(shape, scale); } @@ -81,7 +82,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Weibull(double shape, double scale, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(shape, scale); } @@ -147,7 +148,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Distributions/Wishart.cs b/src/Numerics/Distributions/Wishart.cs index b7fe2987..406f558e 100644 --- a/src/Numerics/Distributions/Wishart.cs +++ b/src/Numerics/Distributions/Wishart.cs @@ -33,6 +33,7 @@ using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra.Factorization; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -74,7 +75,7 @@ namespace MathNet.Numerics.Distributions /// The scale matrix (V) for the Wishart distribution. public Wishart(double degreesOfFreedom, Matrix scale) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(degreesOfFreedom, scale); } @@ -86,7 +87,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Wishart(double degreesOfFreedom, Matrix scale, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(degreesOfFreedom, scale); } diff --git a/src/Numerics/Distributions/Zipf.cs b/src/Numerics/Distributions/Zipf.cs index a39a03cd..e8346882 100644 --- a/src/Numerics/Distributions/Zipf.cs +++ b/src/Numerics/Distributions/Zipf.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using MathNet.Numerics.Properties; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Distributions { @@ -68,7 +69,7 @@ namespace MathNet.Numerics.Distributions /// The n parameter of the distribution. public Zipf(double s, int n) { - _random = new System.Random(Random.RandomSeed.Guid()); + _random = MersenneTwister.Default; SetParameters(s, n); } @@ -80,7 +81,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator which is used to draw random samples. public Zipf(double s, int n, System.Random randomSource) { - _random = randomSource ?? new System.Random(Random.RandomSeed.Guid()); + _random = randomSource ?? MersenneTwister.Default; SetParameters(s, n); } @@ -145,7 +146,7 @@ namespace MathNet.Numerics.Distributions public System.Random RandomSource { get { return _random; } - set { _random = value ?? new System.Random(Random.RandomSeed.Guid()); } + set { _random = value ?? MersenneTwister.Default; } } /// diff --git a/src/Numerics/Statistics/MCMC/HybridMC.cs b/src/Numerics/Statistics/MCMC/HybridMC.cs index 0660572a..61411197 100644 --- a/src/Numerics/Statistics/MCMC/HybridMC.cs +++ b/src/Numerics/Statistics/MCMC/HybridMC.cs @@ -31,6 +31,7 @@ using System; using System.Linq; using MathNet.Numerics.Distributions; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Statistics.Mcmc { @@ -84,7 +85,7 @@ namespace MathNet.Numerics.Statistics.Mcmc /// The number of iterations in between returning samples. /// When the number of burnInterval iteration is negative. public HybridMC(double[] x0, DensityLn pdfLnP, int frogLeapSteps, double stepSize, int burnInterval = 0) - : this(x0, pdfLnP, frogLeapSteps, stepSize, burnInterval, new double[x0.Count()], new System.Random(Random.RandomSeed.Guid()), Grad) + : this(x0, pdfLnP, frogLeapSteps, stepSize, burnInterval, new double[x0.Count()], MersenneTwister.Default, Grad) { for (int i = 0; i < _length; i++) { @@ -108,7 +109,7 @@ namespace MathNet.Numerics.Statistics.Mcmc /// the components of the momentum. /// When the number of burnInterval iteration is negative. public HybridMC(double[] x0, DensityLn pdfLnP, int frogLeapSteps, double stepSize, int burnInterval, double[] pSdv) - : this(x0, pdfLnP, frogLeapSteps, stepSize, burnInterval, pSdv, new System.Random(Random.RandomSeed.Guid())) + : this(x0, pdfLnP, frogLeapSteps, stepSize, burnInterval, pSdv, MersenneTwister.Default) { } diff --git a/src/Numerics/Statistics/MCMC/MCMCSampler.cs b/src/Numerics/Statistics/MCMC/MCMCSampler.cs index e9099783..a23f3411 100644 --- a/src/Numerics/Statistics/MCMC/MCMCSampler.cs +++ b/src/Numerics/Statistics/MCMC/MCMCSampler.cs @@ -29,6 +29,7 @@ // using System; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Statistics.Mcmc { @@ -106,7 +107,7 @@ namespace MathNet.Numerics.Statistics.Mcmc { Accepts = 0; Samples = 0; - RandomSource = new System.Random(Random.RandomSeed.Guid()); + RandomSource = MersenneTwister.Default; } /// diff --git a/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs b/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs index 3b9097b3..0c1f9f8a 100644 --- a/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs +++ b/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs @@ -30,6 +30,7 @@ using System; using MathNet.Numerics.Distributions; +using MathNet.Numerics.Random; namespace MathNet.Numerics.Statistics.Mcmc { @@ -82,7 +83,7 @@ namespace MathNet.Numerics.Statistics.Mcmc /// the momentum. /// When the number of burnInterval iteration is negative. public UnivariateHybridMC(double x0, DensityLn pdfLnP, int frogLeapSteps, double stepSize, int burnInterval = 0, double pSdv = 1) - : this(x0, pdfLnP, frogLeapSteps, stepSize, burnInterval, pSdv, new System.Random(Random.RandomSeed.Guid())) + : this(x0, pdfLnP, frogLeapSteps, stepSize, burnInterval, pSdv, MersenneTwister.Default) { }