Skip to content

Commit

Permalink
[rcore] Added GetRandomFloat
Browse files Browse the repository at this point in the history
  • Loading branch information
hexmaster111 authored Jan 1, 2025
1 parent 0f6e85a commit 389c9f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 389c9f9

Please sign in to comment.