Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rcore] Added GetRandomFloat #4653

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading