From bfca304aaec0fe0f1c4112930c6611cd89c66955 Mon Sep 17 00:00:00 2001 From: Marcus Cuda Date: Sun, 19 Sep 2010 20:52:36 +0800 Subject: [PATCH] added missing parameter check to Xorshift --- src/Numerics/Random/Palf.cs | 2 +- src/Numerics/Random/Xorshift.cs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Numerics/Random/Palf.cs b/src/Numerics/Random/Palf.cs index 42c3c28a..c74f3988 100644 --- a/src/Numerics/Random/Palf.cs +++ b/src/Numerics/Random/Palf.cs @@ -46,7 +46,7 @@ namespace MathNet.Numerics.Random public class Palf : AbstractRandomNumberGenerator { /// - /// Dafult value for the ShortLag + /// Default value for the ShortLag /// private const int DefaultShortLag = 418; diff --git a/src/Numerics/Random/Xorshift.cs b/src/Numerics/Random/Xorshift.cs index 73d83ee3..621cacef 100644 --- a/src/Numerics/Random/Xorshift.cs +++ b/src/Numerics/Random/Xorshift.cs @@ -67,6 +67,7 @@ namespace MathNet.Numerics.Random /// If the seed value is zero, it is set to one. Uses the /// value of to /// set whether the instance is thread safe. + /// Note: must be less than . /// public Xorshift(long a, long c, long x1, long x2) : this((int)DateTime.Now.Ticks, a, c, x1, x2) @@ -100,6 +101,7 @@ namespace MathNet.Numerics.Random /// The initial carry value. /// The initial value if X1. /// The initial value if X2. + /// must be less than . public Xorshift(bool threadSafe, long a, long c, long x1, long x2) : this((int)DateTime.Now.Ticks, threadSafe, a, c, x1, x2) { @@ -134,6 +136,7 @@ namespace MathNet.Numerics.Random /// The initial carry value. /// The initial value if X1. /// The initial value if X2. + /// must be less than . public Xorshift(int seed, long a, long c, long x1, long x2) : this(seed, Control.ThreadSafeRandomNumberGenerators, a, c, x1, x2) { @@ -175,6 +178,7 @@ namespace MathNet.Numerics.Random /// The initial carry value. /// The initial value if X1. /// The initial value if X2. + /// must be less than . public Xorshift(int seed, bool threadSafe, long a, long c, long x1, long x2) : base(threadSafe) { @@ -183,6 +187,11 @@ namespace MathNet.Numerics.Random seed = 1; } + if (a > c) + { + throw new ArgumentException("a must be less than c", "a"); + } + _x = (uint)seed; _y = (ulong)x1; _z = (ulong)x2;