diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj
index 26448f4b..12a8c481 100644
--- a/src/Numerics/Numerics.csproj
+++ b/src/Numerics/Numerics.csproj
@@ -103,8 +103,14 @@
Resources.resx
+
+
+
+
+
+
diff --git a/src/Numerics/Random/Mcg31m1.cs b/src/Numerics/Random/Mcg31m1.cs
new file mode 100644
index 00000000..cb69f544
--- /dev/null
+++ b/src/Numerics/Random/Mcg31m1.cs
@@ -0,0 +1,99 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2009 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.Random
+{
+ using System;
+
+ ///
+ /// Multiplicative congruential generator using a modulus of 2^31-1 and a multiplier of 1132489760.
+ ///
+ public partial class Mcg31m1 : AbstractRandomNumberGenerator
+ {
+ private const ulong _modulus = 2147483647;
+ private const ulong _multiplier = 1132489760;
+ private const double _reciprocal = 1.0 / _modulus;
+ private ulong _xn;
+
+ ///
+ /// Initializes a new instance of the class using
+ /// the current time as the seed.
+ ///
+ public Mcg31m1() : this((int) DateTime.Now.Ticks)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class using
+ /// the current time as the seed.
+ ///
+ /// if set to true , the class is thread safe.
+ public Mcg31m1(bool threadSafe) : this((int)DateTime.Now.Ticks, threadSafe)
+ {
+
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The seed value.
+ /// If the seed value is zero, it is set to one. Uses the
+ /// value of to
+ /// set whether the instance is thread safe.
+ public Mcg31m1(int seed) : this(seed, Control.ThreadSafeRandomNumberGenerators)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The seed value.
+ /// if set to true, the class is thread safe.
+ public Mcg31m1(int seed, bool threadSafe) : base(threadSafe)
+ {
+ if (seed == 0)
+ {
+ seed = 1;
+ }
+ _xn = (uint) seed%_modulus;
+ }
+
+ ///
+ /// Returns a random number between 0.0 and 1.0.
+ ///
+ ///
+ /// A double-precision floating point number greater than or equal to 0.0, and less than 1.0.
+ ///
+ protected override double DoSample()
+ {
+ double ret = _xn*_reciprocal;
+ _xn = (_xn*_multiplier)%_modulus;
+ return ret;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Numerics/Random/Mcg59.cs b/src/Numerics/Random/Mcg59.cs
new file mode 100644
index 00000000..b2c0f424
--- /dev/null
+++ b/src/Numerics/Random/Mcg59.cs
@@ -0,0 +1,100 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2009 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.Random
+{
+ using System;
+
+ ///
+ /// Multiplicative congruential generator using a modulus of 2^59 and a multiplier of 13^13.
+ ///
+ public partial class Mcg59 : AbstractRandomNumberGenerator
+ {
+ private const double _reciprocal = 1.0 / _modulus;
+ private const ulong _modulus = 576460752303423488;
+ private const ulong _multiplier = 302875106592253;
+ private ulong _xn;
+
+ ///
+ /// Initializes a new instance of the class using
+ /// the current time as the seed.
+ ///
+ public Mcg59() : this((int) DateTime.Now.Ticks)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class using
+ /// the current time as the seed.
+ ///
+ /// if set to true , the class is thread safe.
+ public Mcg59(bool threadSafe) : this((int)DateTime.Now.Ticks, threadSafe)
+ {
+
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The seed value.
+ /// If the seed value is zero, it is set to one. Uses the
+ /// value of to
+ /// set whether the instance is thread safe.
+ public Mcg59(int seed) : this(seed, Control.ThreadSafeRandomNumberGenerators)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The seed value.
+ /// The seed is set to 1, if the zero is used as the seed.
+ /// if set to true , the class is thread safe.
+ public Mcg59(int seed, bool threadSafe) : base(threadSafe)
+ {
+ if( seed == 0)
+ {
+ seed = 1;
+ }
+ _xn = (uint) seed % _modulus;
+ }
+
+ ///
+ /// Returns a random number between 0.0 and 1.0.
+ ///
+ ///
+ /// A double-precision floating point number greater than or equal to 0.0, and less than 1.0.
+ ///
+ protected override double DoSample()
+ {
+ double ret = _xn * _reciprocal;
+ _xn = (_xn * _multiplier) % _modulus;
+ return ret;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Numerics/Random/Mrg32k3a.cs b/src/Numerics/Random/Mrg32k3a.cs
new file mode 100644
index 00000000..ce45c1b7
--- /dev/null
+++ b/src/Numerics/Random/Mrg32k3a.cs
@@ -0,0 +1,136 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2009 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.Random
+{
+ using System;
+
+ ///
+ /// A 32-bit combined multiple recursive generator with 2 components of order 3.
+ ///
+ ///Based off of P. L'Ecuyer, "Combined Multiple Recursive Random Number Generators," Operations Research, 44, 5 (1996), 816--822.
+ public partial class Mrg32k3a : AbstractRandomNumberGenerator
+ {
+ ///
+ /// Initializes a new instance of the class using
+ /// the current time as the seed.
+ ///
+ /// If the seed value is zero, it is set to one. Uses the
+ /// value of to
+ /// set whether the instance is thread safe.
+ public Mrg32k3a() : this((int)DateTime.Now.Ticks)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class using
+ /// the current time as the seed.
+ ///
+ /// if set to true , the class is thread safe.
+ public Mrg32k3a(bool threadSafe) : this((int)DateTime.Now.Ticks, threadSafe)
+ {
+ }
+ private const double _a12 = 1403580;
+ private const double _a13 = 810728;
+ private const double _a21 = 527612;
+ private const double _a23 = 1370589;
+ private const double _modulus1 = 4294967087;
+ private const double _modulus2 = 4294944443;
+
+ private const double _reciprocal = 1.0/_modulus1;
+ private double _xn1 = 1;
+ private double _xn2 = 1;
+ private double _xn3;
+ private double _yn1 = 1;
+ private double _yn2 = 1;
+ private double _yn3 = 1;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The seed value.
+ /// If the seed value is zero, it is set to one. Uses the
+ /// value of to
+ /// set whether the instance is thread safe.
+ public Mrg32k3a(int seed) : this(seed, Control.ThreadSafeRandomNumberGenerators)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The seed value.
+ /// if set to true, the class is thread safe.
+ public Mrg32k3a(int seed, bool threadSafe) : base(threadSafe)
+ {
+ if (seed == 0)
+ {
+ seed = 1;
+ }
+ _xn3 = (uint)seed;
+ }
+
+
+ ///
+ /// Returns a random number between 0.0 and 1.0.
+ ///
+ ///
+ /// A double-precision floating point number greater than or equal to 0.0, and less than 1.0.
+ ///
+ protected override double DoSample()
+ {
+ double xn = _a12*_xn2 - _a13*_xn3;
+ double k = (long) (xn/_modulus1);
+ xn -= k*_modulus1;
+ if (xn < 0)
+ {
+ xn += _modulus1;
+ }
+
+ double yn = _a21*_yn1 - _a23*_yn3;
+ k = (long) (yn/_modulus2);
+ yn -= k*_modulus2;
+ if (yn < 0)
+ {
+ yn += _modulus2;
+ }
+ _xn3 = _xn2;
+ _xn2 = _xn1;
+ _xn1 = xn;
+ _yn3 = _yn2;
+ _yn2 = _yn1;
+ _yn1 = yn;
+
+ if (xn <= yn)
+ {
+ return (xn - yn + _modulus1)*_reciprocal;
+ }
+ return (xn - yn)*_reciprocal;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Numerics/Random/SystemCrypto.cs b/src/Numerics/Random/SystemCrypto.cs
new file mode 100644
index 00000000..4f385eb8
--- /dev/null
+++ b/src/Numerics/Random/SystemCrypto.cs
@@ -0,0 +1,98 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2009 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.Random
+{
+ using System;
+ using System.Security.Cryptography;
+
+ ///
+ /// A random number generator based on the class in the .NET library.
+ ///
+ public class SystemCryptoRandomNumberGenerator : AbstractRandomNumberGenerator
+ {
+ private const double mReciprocal = 1.0 / uint.MaxValue;
+ private readonly RandomNumberGenerator mRandom;
+
+ ///
+ /// Construct a new random number generator with a random seed.
+ ///
+ /// Uses and uses the value of
+ /// to set whether the instance is thread safe.
+ public SystemCryptoRandomNumberGenerator(): this(new RNGCryptoServiceProvider(), Control.ThreadSafeRandomNumberGenerators)
+ {
+ mRandom = new RNGCryptoServiceProvider();
+ }
+
+ ///
+ /// Construct a new random number generator with random seed.
+ ///
+ /// The to use.
+ /// Uses the value of to set whether the instance is thread safe.
+ public SystemCryptoRandomNumberGenerator(RandomNumberGenerator rng) : this(rng, Control.ThreadSafeRandomNumberGenerators)
+ {
+ }
+
+ ///
+ /// Construct a new random number generator with random seed.
+ ///
+ /// Uses
+ /// if set to true , the class is thread safe.
+ public SystemCryptoRandomNumberGenerator(bool threadSafe): this(new RNGCryptoServiceProvider(), threadSafe)
+ {
+ }
+
+ ///
+ /// Construct a new random number generator with random seed.
+ ///
+ /// The to use.
+ /// if set to true , the class is thread safe.
+ public SystemCryptoRandomNumberGenerator(RandomNumberGenerator rng, bool threadSafe) : base(threadSafe)
+ {
+ if (rng == null)
+ {
+ throw new ArgumentNullException("rng");
+ }
+ mRandom = rng;
+ }
+
+
+ ///
+ /// Returns a random number between 0.0 and 1.0.
+ ///
+ ///
+ /// A double-precision floating point number greater than or equal to 0.0, and less than 1.0.
+ ///
+ protected override double DoSample()
+ {
+ byte[] bytes = new byte[4];
+ mRandom.GetBytes(bytes);
+ return BitConverter.ToUInt32(bytes, 0) * mReciprocal;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Numerics/Random/WH1982.cs b/src/Numerics/Random/WH1982.cs
new file mode 100644
index 00000000..2593e5b5
--- /dev/null
+++ b/src/Numerics/Random/WH1982.cs
@@ -0,0 +1,113 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2009 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.Random
+{
+ using System;
+
+ ///
+ /// Wichmann-Hill’s 1982 combined multiplicative congruential generator.
+ ///
+ /// See: Wichmann, B. A. & Hill, I. D. (1982), "Algorithm AS 183:
+ /// An efficient and portable pseudo-random number generator". Applied Statistics 31 (1982) 188-190
+ ///
+ public class WH1982 : AbstractRandomNumberGenerator
+ {
+ private const uint _modx = 30269;
+ private const double _modx_recip = 1.0/_modx;
+ private const uint _mody = 30307;
+ private const double _mody_recip = 1.0/_mody;
+ private const uint _modz = 30323;
+ private const double _modz_recip = 1.0/_modz;
+ private uint _xn;
+ private uint _yn = 1;
+ private uint _zn = 1;
+
+ ///
+ /// Initializes a new instance of the class using
+ /// the current time as the seed.
+ ///
+ public WH1982() : this((int) DateTime.Now.Ticks)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class using
+ /// the current time as the seed.
+ ///
+ /// if set to true , the class is thread safe.
+ public WH1982(bool threadSafe)
+ : this((int) DateTime.Now.Ticks, threadSafe)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The seed value.
+ /// If the seed value is zero, it is set to one. Uses the
+ /// value of to
+ /// set whether the instance is thread safe.
+ public WH1982(int seed) : this(seed, Control.ThreadSafeRandomNumberGenerators)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The seed value.
+ /// The seed is set to 1, if the zero is used as the seed.
+ /// if set to true , the class is thread safe.
+ public WH1982(int seed, bool threadSafe)
+ : base(threadSafe)
+ {
+ if (seed == 0)
+ {
+ seed = 1;
+ }
+ _xn = (uint) seed%_modx;
+ }
+
+ ///
+ /// Returns a random number between 0.0 and 1.0.
+ ///
+ ///
+ /// A double-precision floating point number greater than or equal to 0.0, and less than 1.0.
+ ///
+ protected override double DoSample()
+ {
+ _xn = (171*_xn)%_modx;
+ _yn = (172*_yn)%_mody;
+ _zn = (170*_zn)%_modz;
+
+ double w = _xn*_modx_recip + _yn*_mody_recip + _zn*_modz_recip;
+ w -= (int) w;
+ return w;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Numerics/Random/WH2006.cs b/src/Numerics/Random/WH2006.cs
new file mode 100644
index 00000000..c86a3216
--- /dev/null
+++ b/src/Numerics/Random/WH2006.cs
@@ -0,0 +1,117 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2009 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.Random
+{
+ using System;
+
+ ///
+ /// Wichmann-Hill’s 2006 combined multiplicative congruential generator.
+ ///
+ /// See: Wichmann, B. A. & Hill, I. D. (2006), "Generating good pseudo-random numbers".
+ /// Computational Statistics & Data Analysis 51:3 (2006) 1614-1622
+ ///
+ public class WH2006 : AbstractRandomNumberGenerator
+ {
+ private const uint _modw = 2147483123;
+ private const double _modw_recip = 1.0/_modw;
+ private const uint _modx = 2147483579;
+ private const double _modx_recip = 1.0/_modx;
+ private const uint _mody = 2147483543;
+ private const double _mody_recip = 1.0/_mody;
+ private const uint _modz = 2147483423;
+ private const double _modz_recip = 1.0/_modz;
+ private ulong _wn = 1;
+ private ulong _xn;
+ private ulong _yn = 1;
+ private ulong _zn = 1;
+
+ ///
+ /// Initializes a new instance of the class using
+ /// the current time as the seed.
+ ///
+ public WH2006() : this((int) DateTime.Now.Ticks)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class using
+ /// the current time as the seed.
+ ///
+ /// if set to true , the class is thread safe.
+ public WH2006(bool threadSafe)
+ : this((int) DateTime.Now.Ticks, threadSafe)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The seed value.
+ /// If the seed value is zero, it is set to one. Uses the
+ /// value of to
+ /// set whether the instance is thread safe.
+ public WH2006(int seed) : this(seed, Control.ThreadSafeRandomNumberGenerators)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The seed value.
+ /// The seed is set to 1, if the zero is used as the seed.
+ /// if set to true , the class is thread safe.
+ public WH2006(int seed, bool threadSafe)
+ : base(threadSafe)
+ {
+ if (seed == 0)
+ {
+ seed = 1;
+ }
+ _xn = (uint) seed%_modx;
+ }
+
+ ///
+ /// Returns a random number between 0.0 and 1.0.
+ ///
+ ///
+ /// A double-precision floating point number greater than or equal to 0.0, and less than 1.0.
+ ///
+ protected override double DoSample()
+ {
+ _xn = 11600*_xn%_modx;
+ _yn = 47003*_yn%_mody;
+ _zn = 23000*_zn%_modz;
+ _wn = 33000*_wn%_modw;
+
+ double u = _xn*_modx_recip + _yn*_mody_recip + _zn*_modz_recip + _wn*_modw_recip;
+ u -= (int) u;
+ return u;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Numerics/SpecialFunctions.cs b/src/Numerics/SpecialFunctions.cs
index 1bb90334..0e1ce812 100644
--- a/src/Numerics/SpecialFunctions.cs
+++ b/src/Numerics/SpecialFunctions.cs
@@ -29,6 +29,7 @@
namespace MathNet.Numerics
{
using System;
+ using Properties;
///
/// This class implements a collection of special function evaluations for double precision. This class
@@ -66,13 +67,57 @@ namespace MathNet.Numerics
};
///
- /// Static Initializer for all special function routines
+ /// Initializes static members of the SpecialFunctions class.
///
static SpecialFunctions()
{
InitializeFactorial();
}
+ ///
+ /// Computes the 'th Harmonic number.
+ ///
+ /// The Harmonic number which needs to be computed.
+ /// The t'th Harmonic number.
+ public static double Harmonic(int t)
+ {
+ return Constants.EulerMascheroni + DiGamma(t + 1.0);
+ }
+
+ ///
+ /// Computes the logarithm of the Euler Beta function.
+ ///
+ /// A positive real number.
+ /// A positive real number.
+ /// The logarithm of the Euler Beta function evaluated at z,w.
+ /// If or are not positive.
+ public static double BetaLn(double z, double w)
+ {
+ if (z <= 0.0)
+ {
+ throw new ArgumentException(Resources.ArgumentMustBePositive, "z");
+ }
+
+ if (w <= 0.0)
+ {
+ throw new ArgumentException(Resources.ArgumentMustBePositive, "w");
+ }
+
+ return GammaLn(z) + GammaLn(w) - GammaLn(z + w);
+ }
+
+ ///
+ /// Computes the Euler Beta function.
+ ///
+ /// The first Beta parameter, a positive real number.
+ /// The second Beta parameter, a positive real number.
+ /// The Euler Beta function evaluated at z,w.
+ /// If or are not positive.
+ public static double Beta(double z, double w)
+ {
+ return System.Math.Exp(BetaLn(z, w));
+ }
+
///
/// Computes the logarithm of the Gamma function.
///
@@ -235,6 +280,16 @@ namespace MathNet.Numerics
return Double.NaN;
}
+ if (Double.IsNegativeInfinity(p))
+ {
+ return 0.0;
+ }
+
+ if (Double.IsPositiveInfinity(p))
+ {
+ return Double.PositiveInfinity;
+ }
+
double x = Math.Exp(p);
for (double d = 1.0; d > 1.0e-15; d /= 2.0)
{
@@ -249,11 +304,6 @@ namespace MathNet.Numerics
throw new NotImplementedException();
}
- public static double BetaLn(double a, double b)
- {
- throw new NotImplementedException();
- }
-
public static double BetaRegularized(double a, double b, double x)
{
throw new NotImplementedException();
diff --git a/src/UnitTests/Random/Mcg31m1Tests.cs b/src/UnitTests/Random/Mcg31m1Tests.cs
new file mode 100644
index 00000000..f27a2daa
--- /dev/null
+++ b/src/UnitTests/Random/Mcg31m1Tests.cs
@@ -0,0 +1,39 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2009 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.UnitTests.RandomTests
+{
+ using MbUnit.Framework;
+ using MathNet.Numerics.Random;
+
+ [TestFixture]
+ public class Mcg31m1Tests : RandomTests
+ {
+ public Mcg31m1Tests() : base(typeof(Mcg31m1)){}
+ }
+}
diff --git a/src/UnitTests/Random/Mcg59Tests.cs b/src/UnitTests/Random/Mcg59Tests.cs
new file mode 100644
index 00000000..601259bf
--- /dev/null
+++ b/src/UnitTests/Random/Mcg59Tests.cs
@@ -0,0 +1,39 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2009 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.UnitTests.RandomTests
+{
+ using MbUnit.Framework;
+ using MathNet.Numerics.Random;
+
+ [TestFixture]
+ public class Mcg59Tests : RandomTests
+ {
+ public Mcg59Tests() : base(typeof(Mcg59)) { }
+ }
+}
diff --git a/src/UnitTests/Random/MersenneTwisterTests.cs b/src/UnitTests/Random/MersenneTwisterTests.cs
index 6b5a4375..9a28c5dd 100644
--- a/src/UnitTests/Random/MersenneTwisterTests.cs
+++ b/src/UnitTests/Random/MersenneTwisterTests.cs
@@ -1,4 +1,4 @@
-//
+//
// Math.NET Numerics, part of the Math.NET Project
// http://mathnet.opensourcedotnet.info
//
diff --git a/src/UnitTests/Random/Mrg32k3aTests.cs b/src/UnitTests/Random/Mrg32k3aTests.cs
new file mode 100644
index 00000000..d1e5ceb0
--- /dev/null
+++ b/src/UnitTests/Random/Mrg32k3aTests.cs
@@ -0,0 +1,41 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2009 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.UnitTests.RandomTests
+{
+ using MbUnit.Framework;
+ using MathNet.Numerics.Random;
+
+ [TestFixture]
+ public class Mrg32k3aTests : RandomTests
+ {
+ public Mrg32k3aTests() : base(typeof (Mrg32k3a))
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/UnitTests/Random/SystemCryptoTests.cs b/src/UnitTests/Random/SystemCryptoTests.cs
new file mode 100644
index 00000000..7f850380
--- /dev/null
+++ b/src/UnitTests/Random/SystemCryptoTests.cs
@@ -0,0 +1,41 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2009 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.UnitTests.RandomTests
+{
+ using MbUnit.Framework;
+ using MathNet.Numerics.Random;
+
+ [TestFixture]
+ public class SystemCryptoRandomNumberGeneratorTests : RandomTests
+ {
+ public SystemCryptoRandomNumberGeneratorTests() : base(typeof (SystemCryptoRandomNumberGenerator))
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/UnitTests/Random/WH1982Tests.cs b/src/UnitTests/Random/WH1982Tests.cs
new file mode 100644
index 00000000..eed86615
--- /dev/null
+++ b/src/UnitTests/Random/WH1982Tests.cs
@@ -0,0 +1,42 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2009 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.UnitTests.RandomTests
+{
+ using MbUnit.Framework;
+ using MathNet.Numerics.Random;
+
+ [TestFixture]
+ public class WH1982Tests : RandomTests
+ {
+ public WH1982Tests()
+ : base(typeof (WH1982))
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/UnitTests/Random/WH2006Tests.cs b/src/UnitTests/Random/WH2006Tests.cs
new file mode 100644
index 00000000..d6916b5f
--- /dev/null
+++ b/src/UnitTests/Random/WH2006Tests.cs
@@ -0,0 +1,42 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2009 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.UnitTests.RandomTests
+{
+ using MbUnit.Framework;
+ using MathNet.Numerics.Random;
+
+ [TestFixture]
+ public class WH2006Tests : RandomTests
+ {
+ public WH2006Tests()
+ : base(typeof(WH2006))
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj
index 469019aa..1ee5804e 100644
--- a/src/UnitTests/UnitTests.csproj
+++ b/src/UnitTests/UnitTests.csproj
@@ -94,9 +94,15 @@
+
+
+
+
+
+