[rcore] Added GetRandomFloat
This commit is contained in:
parent
0f6e85a975
commit
389c9f9de5
|
|
@ -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
|
||||
|
||||
|
|
|
|||
14
src/rcore.c
14
src/rcore.c
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user