From e3560ee73218ab436d530b99c4bba7429a0eea68 Mon Sep 17 00:00:00 2001 From: Kyle Anders Date: Fri, 13 Oct 2023 10:41:57 -0700 Subject: [PATCH] Added function SetRandomSeedWithTime This function seeds the random number generator using the time since epoch, allowing for a unique seed from within the library. --- src/raylib.h | 3 ++- src/rcore.c | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index c03e0a576..fbfaabb75 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1055,7 +1055,8 @@ RLAPI void WaitTime(double seconds); // Wait for so // Misc. functions RLAPI int GetRandomValue(int min, int max); // Get a random value between min and max (both included) -RLAPI void SetRandomSeed(unsigned int seed); // Set the seed for the random number generator +RLAPI void SetRandomSeed(unsigned int seed); // Set the seed for the random number generator using custom value. +RLAPI void SetRandomSeedWithTime(void); // Set the seed for the random number generator using time since epoch. RLAPI void TakeScreenshot(const char *fileName); // Takes a screenshot of current screen (filename extension defines format) RLAPI void SetConfigFlags(unsigned int flags); // Setup init configuration flags (view FLAGS) RLAPI void OpenURL(const char *url); // Open URL with default system browser (if available) diff --git a/src/rcore.c b/src/rcore.c index 3efa67b2c..54cef3b9a 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1338,12 +1338,18 @@ int GetRandomValue(int min, int max) return (rand()%(abs(max - min) + 1) + min); } -// Set the seed for the random number generator +// Set the seed for the random number generator using custom value. void SetRandomSeed(unsigned int seed) { srand(seed); } +// Set the seed for the random number generator using time since epoch. +void SetRandomSeedWithTime(void) +{ + srand((unsigned int)time(NULL)); +} + // Takes a screenshot of current screen (saved a .png) void TakeScreenshot(const char *fileName) {