diff --git a/src/Random.cs b/src/Random.cs index a6fb7b7..385bfb2 100644 --- a/src/Random.cs +++ b/src/Random.cs @@ -112,7 +112,7 @@ namespace MoonTools.ECS // .NET Random API always returns a non-negative signed int. Fun! public int Next() { - return (int) (NextInternal() >> 1); // bitshift right to get rid of signed bit + return (int) (NextInternal() >>> 1); // unsigned bitshift right to get rid of signed bit } public int Next(int n) @@ -130,8 +130,9 @@ namespace MoonTools.ECS public long NextInt64() { long next = NextInternal(); - next <<= 31; + next <<= 32; next |= NextInternal(); + next >>>= 1; return next; } @@ -148,6 +149,12 @@ namespace MoonTools.ECS return min + next; } + public float NextFloat() + { + var n = NextInternal(); + return ((float) n) / uint.MaxValue; + } + public double NextDouble() { var n = NextInternal();