Added function SetRandomSeedWithTime

This function seeds the random number generator using the time since
epoch, allowing for a unique seed from within the library.
This commit is contained in:
Kyle Anders 2023-10-13 10:41:57 -07:00
parent 0f4a8cf7cb
commit e3560ee732
2 changed files with 9 additions and 2 deletions

View File

@ -1055,7 +1055,8 @@ RLAPI void WaitTime(double seconds); // Wait for so
// Misc. functions // Misc. functions
RLAPI int GetRandomValue(int min, int max); // Get a random value between min and max (both included) 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 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 SetConfigFlags(unsigned int flags); // Setup init configuration flags (view FLAGS)
RLAPI void OpenURL(const char *url); // Open URL with default system browser (if available) RLAPI void OpenURL(const char *url); // Open URL with default system browser (if available)

View File

@ -1338,12 +1338,18 @@ int GetRandomValue(int min, int max)
return (rand()%(abs(max - min) + 1) + min); 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) void SetRandomSeed(unsigned int seed)
{ {
srand(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) // Takes a screenshot of current screen (saved a .png)
void TakeScreenshot(const char *fileName) void TakeScreenshot(const char *fileName)
{ {