mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-24 13:39:11 +00:00
Moved SDL_rand auto-initialization out of SDL_rand_r
This commit is contained in:
parent
421326b6da
commit
f4ee59a1a2
1 changed files with 9 additions and 5 deletions
|
@ -23,14 +23,22 @@
|
|||
/* This file contains portable random functions for SDL */
|
||||
|
||||
static Uint64 SDL_rand_state;
|
||||
static SDL_bool SDL_rand_initialized = SDL_FALSE;
|
||||
|
||||
void SDL_srand(Uint64 seed)
|
||||
{
|
||||
if (!seed) {
|
||||
seed = SDL_GetPerformanceCounter();
|
||||
}
|
||||
SDL_rand_state = seed;
|
||||
SDL_rand_initialized = SDL_TRUE;
|
||||
}
|
||||
|
||||
Uint32 SDL_rand(void)
|
||||
{
|
||||
if(!SDL_rand_initialized) {
|
||||
SDL_srand(0);
|
||||
}
|
||||
return SDL_rand_r(&SDL_rand_state);
|
||||
}
|
||||
|
||||
|
@ -62,10 +70,6 @@ Uint32 SDL_rand_r(Uint64 *state)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (!*state) {
|
||||
*state = SDL_GetPerformanceCounter();
|
||||
}
|
||||
|
||||
// Multiplier from Table 6 of
|
||||
// Steele GL, Vigna S. Computationally easy, spectrally good multipliers
|
||||
// for congruential pseudorandom number generators.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue