fix random sometimes returning negative integers
parent
855b8d6487
commit
35934baec0
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue