Revert "Add simple safety checks to RNG"

This reverts commit 202c94f02e.
This commit is contained in:
Lwmte 2024-11-24 13:20:56 +01:00
parent a74bb4e584
commit 19be42911c
2 changed files with 10 additions and 22 deletions

View file

@ -8,33 +8,21 @@
namespace TEN::Math::Random namespace TEN::Math::Random
{ {
static auto Generator = std::mt19937(); static std::mt19937 Engine;
int GenerateInt(int min, int max) int GenerateInt(int low, int high)
{ {
if (min >= max) return (Engine() / (Engine.max() / (high - low + 1) + 1) + low);
{
TENLog("Attempted to generate integer with minimum value greater than maximum value.", LogLevel::Warning);
return min;
}
return (((Generator() / (Generator.max()) / (max - min + 1)) + 1) + min);
} }
float GenerateFloat(float min, float max) float GenerateFloat(float low, float high)
{ {
if (min >= max) return ((high - low) * Engine() / Engine.max() + low);
{
TENLog("Attempted to generate float with minimum value greater than maximum value.", LogLevel::Warning);
return min;
}
return ((((max - min) * Generator()) / Generator.max()) + min);
} }
short GenerateAngle(short min, short max) short GenerateAngle(short low, short high)
{ {
return (short)GenerateInt(min, min); return (short)GenerateInt(low, high);
} }
Vector2 GenerateDirection2D() Vector2 GenerateDirection2D()

View file

@ -6,9 +6,9 @@ namespace TEN::Math::Random
{ {
// Value generation // Value generation
int GenerateInt(int min = 0, int max = SHRT_MAX); int GenerateInt(int low = 0, int high = SHRT_MAX);
float GenerateFloat(float min = 0.0f, float max = 1.0f); float GenerateFloat(float low = 0.0f, float high = 1.0f);
short GenerateAngle(short min = SHRT_MIN, short max = SHRT_MAX); short GenerateAngle(short low = SHRT_MIN, short high = SHRT_MAX);
// 2D geometric generation // 2D geometric generation