[rcore] Added GetRandomFloat

This commit is contained in:
__hexmaster111 2025-01-01 07:31:07 -06:00 committed by GitHub
parent 0f6e85a975
commit 389c9f9de5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -1092,6 +1092,7 @@ RLAPI void WaitTime(double seconds); // Wait for so
// Random values generation functions
RLAPI void SetRandomSeed(unsigned int seed); // Set the seed for the random number generator
RLAPI int GetRandomValue(int min, int max); // Get a random value between min and max (both included)
RLAPI float GetRandomFloat(float min, float max); // Get a random value between min and max (both included)
RLAPI int *LoadRandomSequence(unsigned int count, int min, int max); // Load random values sequence, no values repeated
RLAPI void UnloadRandomSequence(int *sequence); // Unload random values sequence

View File

@ -1781,6 +1781,20 @@ void SetRandomSeed(unsigned int seed)
#endif
}
// Get a random value between min and max included
float GetRandomFloat(float min, float max)
{
if (min > max)
{
float tmp = max;
max = min;
min = tmp;
}
int r = GetRandomValue(0, RAND_MAX);
return r * (max - min) / RAND_MAX + min;
}
// Get a random value between min and max included
int GetRandomValue(int min, int max)
{