From 389c9f9de5a178e711654a7ecd590e179eb6b234 Mon Sep 17 00:00:00 2001 From: __hexmaster111 Date: Wed, 1 Jan 2025 07:31:07 -0600 Subject: [PATCH] [rcore] Added GetRandomFloat --- src/raylib.h | 1 + src/rcore.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/raylib.h b/src/raylib.h index 45109126..23bc020f 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -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 diff --git a/src/rcore.c b/src/rcore.c index 2806235c..8c87fb68 100644 --- a/src/rcore.c +++ b/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) {