Fix #5675
This commit is contained in:
@@ -12,10 +12,10 @@ using System;
|
|||||||
|
|
||||||
namespace OpenRA.Support
|
namespace OpenRA.Support
|
||||||
{
|
{
|
||||||
// quick & dirty Mersenne Twister [MT19937] implementation
|
// Quick & dirty Mersenne Twister [MT19937] implementation
|
||||||
public class MersenneTwister
|
public class MersenneTwister
|
||||||
{
|
{
|
||||||
uint[] mt = new uint[624];
|
readonly uint[] mt = new uint[624];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
public int Last;
|
public int Last;
|
||||||
@@ -46,9 +46,27 @@ namespace OpenRA.Support
|
|||||||
return Last;
|
return Last;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Next(int low, int high) { return low + Next() % (high - low); }
|
public int Next(int low, int high)
|
||||||
public int Next(int high) { return Next() % high; }
|
{
|
||||||
public float NextFloat() { return Math.Abs(Next() / (float)0x7fffffff); }
|
if (high < low)
|
||||||
|
throw new ArgumentOutOfRangeException("high", "Maximum value is less than the minimum value.");
|
||||||
|
|
||||||
|
var diff = high - low;
|
||||||
|
if (diff <= 1)
|
||||||
|
return low;
|
||||||
|
|
||||||
|
return low + Next() % diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Next(int high)
|
||||||
|
{
|
||||||
|
return Next(0, high);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float NextFloat()
|
||||||
|
{
|
||||||
|
return Math.Abs(Next() / (float)0x7fffffff);
|
||||||
|
}
|
||||||
|
|
||||||
void Generate()
|
void Generate()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user