oecs-sharp/Game.CardWars/Mulberry32.cs

22 lines
568 B
C#

namespace Game.CardWars;
/// <summary>
/// Mulberry32 PRNG — a fast, high-quality 32-bit random number generator.
/// </summary>
public static class Mulberry32
{
public static float NextFloat(ref uint state)
{
state += 0x6D2B79F5u;
uint z = state;
z = (z ^ (z >> 15)) * (z | 1u);
z ^= z + (z ^ (z >> 7)) * (z | 61u);
return (z ^ (z >> 14)) / (float)uint.MaxValue;
}
public static int NextInt(ref uint state, int min, int max)
{
return (int)(NextFloat(ref state) * (max - min + 1)) + min;
}
}