45 lines
707 B
C#
45 lines
707 B
C#
using System;
|
|
|
|
namespace BitStrap
|
|
{
|
|
public class FastRandom
|
|
{
|
|
private const float REAL_UNIT_INT = 4.656613E-10f;
|
|
|
|
private uint x;
|
|
|
|
private uint y;
|
|
|
|
private uint z;
|
|
|
|
private uint w;
|
|
|
|
public FastRandom()
|
|
{
|
|
SetSeed(Environment.TickCount);
|
|
}
|
|
|
|
public int GetNextInt()
|
|
{
|
|
uint num = x ^ (x << 11);
|
|
x = y;
|
|
y = z;
|
|
z = w;
|
|
return (int)(0x7FFFFFFF & (w = w ^ (w >> 19) ^ (num ^ (num >> 8))));
|
|
}
|
|
|
|
public float GetNextFloat()
|
|
{
|
|
return 4.656613E-10f * (float)GetNextInt();
|
|
}
|
|
|
|
public void SetSeed(int seed)
|
|
{
|
|
x = (uint)(seed * 1431655781 + seed * 1183186591 + seed * 622729787 + seed * 338294347);
|
|
y = 842502087u;
|
|
z = 3579807591u;
|
|
w = 273326509u;
|
|
}
|
|
}
|
|
}
|