Browse Source

added missing parameter check to Xorshift

pull/36/head
Marcus Cuda 16 years ago
parent
commit
bfca304aae
  1. 2
      src/Numerics/Random/Palf.cs
  2. 9
      src/Numerics/Random/Xorshift.cs

2
src/Numerics/Random/Palf.cs

@ -46,7 +46,7 @@ namespace MathNet.Numerics.Random
public class Palf : AbstractRandomNumberGenerator public class Palf : AbstractRandomNumberGenerator
{ {
/// <summary> /// <summary>
/// Dafult value for the ShortLag /// Default value for the ShortLag
/// </summary> /// </summary>
private const int DefaultShortLag = 418; private const int DefaultShortLag = 418;

9
src/Numerics/Random/Xorshift.cs

@ -67,6 +67,7 @@ namespace MathNet.Numerics.Random
/// <remarks>If the seed value is zero, it is set to one. Uses the /// <remarks>If the seed value is zero, it is set to one. Uses the
/// value of <see cref="Control.ThreadSafeRandomNumberGenerators"/> to /// value of <see cref="Control.ThreadSafeRandomNumberGenerators"/> to
/// set whether the instance is thread safe. /// set whether the instance is thread safe.
/// Note: <paramref name="c"/> must be less than <paramref name="a"/>.
/// </remarks> /// </remarks>
public Xorshift(long a, long c, long x1, long x2) public Xorshift(long a, long c, long x1, long x2)
: this((int)DateTime.Now.Ticks, a, c, x1, x2) : this((int)DateTime.Now.Ticks, a, c, x1, x2)
@ -100,6 +101,7 @@ namespace MathNet.Numerics.Random
/// <param name="c">The initial carry value.</param> /// <param name="c">The initial carry value.</param>
/// <param name="x1">The initial value if X1.</param> /// <param name="x1">The initial value if X1.</param>
/// <param name="x2">The initial value if X2.</param> /// <param name="x2">The initial value if X2.</param>
/// <remarks><paramref name="c"/> must be less than <paramref name="a"/>.</remarks>
public Xorshift(bool threadSafe, long a, long c, long x1, long x2) public Xorshift(bool threadSafe, long a, long c, long x1, long x2)
: this((int)DateTime.Now.Ticks, threadSafe, a, c, x1, x2) : this((int)DateTime.Now.Ticks, threadSafe, a, c, x1, x2)
{ {
@ -134,6 +136,7 @@ namespace MathNet.Numerics.Random
/// <param name="c">The initial carry value.</param> /// <param name="c">The initial carry value.</param>
/// <param name="x1">The initial value if X1.</param> /// <param name="x1">The initial value if X1.</param>
/// <param name="x2">The initial value if X2.</param> /// <param name="x2">The initial value if X2.</param>
/// <remarks><paramref name="c"/> must be less than <paramref name="a"/>.</remarks>
public Xorshift(int seed, long a, long c, long x1, long x2) public Xorshift(int seed, long a, long c, long x1, long x2)
: this(seed, Control.ThreadSafeRandomNumberGenerators, a, c, x1, x2) : this(seed, Control.ThreadSafeRandomNumberGenerators, a, c, x1, x2)
{ {
@ -175,6 +178,7 @@ namespace MathNet.Numerics.Random
/// <param name="c">The initial carry value.</param> /// <param name="c">The initial carry value.</param>
/// <param name="x1">The initial value if X1.</param> /// <param name="x1">The initial value if X1.</param>
/// <param name="x2">The initial value if X2.</param> /// <param name="x2">The initial value if X2.</param>
/// <remarks><paramref name="c"/> must be less than <paramref name="a"/>.</remarks>
public Xorshift(int seed, bool threadSafe, long a, long c, long x1, long x2) public Xorshift(int seed, bool threadSafe, long a, long c, long x1, long x2)
: base(threadSafe) : base(threadSafe)
{ {
@ -183,6 +187,11 @@ namespace MathNet.Numerics.Random
seed = 1; seed = 1;
} }
if (a > c)
{
throw new ArgumentException("a must be less than c", "a");
}
_x = (uint)seed; _x = (uint)seed;
_y = (ulong)x1; _y = (ulong)x1;
_z = (ulong)x2; _z = (ulong)x2;

Loading…
Cancel
Save