mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-25 16:54:24 +00:00
Added SDL_rand_float and SDL_rand_n to API
This commit is contained in:
committed by
Sam Lantinga
parent
f4ee59a1a2
commit
83d21e20df
@@ -981,6 +981,8 @@
|
||||
#define SDL_qsort SDL_qsort_REAL
|
||||
#define SDL_qsort_r SDL_qsort_r_REAL
|
||||
#define SDL_rand SDL_rand_REAL
|
||||
#define SDL_rand_float SDL_rand_float_REAL
|
||||
#define SDL_rand_n SDL_rand_n_REAL
|
||||
#define SDL_rand_r SDL_rand_r_REAL
|
||||
#define SDL_realloc SDL_realloc_REAL
|
||||
#define SDL_round SDL_round_REAL
|
||||
|
||||
@@ -990,6 +990,8 @@ SDL_DYNAPI_PROC(float,SDL_powf,(float a, float b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_qsort,(void *a, size_t b, size_t c, SDL_CompareCallback d),(a,b,c,d),)
|
||||
SDL_DYNAPI_PROC(void,SDL_qsort_r,(void *a, size_t b, size_t c, SDL_CompareCallback_r d, void *e),(a,b,c,d,e),)
|
||||
SDL_DYNAPI_PROC(Uint32,SDL_rand,(void),(),return)
|
||||
SDL_DYNAPI_PROC(float,SDL_rand_float,(void),(),return)
|
||||
SDL_DYNAPI_PROC(Uint32,SDL_rand_n,(Uint32 a),(a),return)
|
||||
SDL_DYNAPI_PROC(Uint32,SDL_rand_r,(Uint64 *a),(a),return)
|
||||
SDL_DYNAPI_PROC(void*,SDL_realloc,(void *a, size_t b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(double,SDL_round,(double a),(a),return)
|
||||
|
||||
@@ -42,20 +42,13 @@ Uint32 SDL_rand(void)
|
||||
return SDL_rand_r(&SDL_rand_state);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a number between [0, n)
|
||||
* Fast but slightly biased. Don't run your casino with this.
|
||||
*/
|
||||
Sint32 SDL_rand_n(Sint32 n)
|
||||
Uint32 SDL_rand_n(Uint32 n)
|
||||
{
|
||||
// On 32-bit arch, the compiler will optimize to a single 32-bit multiply
|
||||
Uint64 val = (Uint64)SDL_rand() * n;
|
||||
return (Sint32)(val >> 32);
|
||||
return (Uint32)(val >> 32);
|
||||
}
|
||||
|
||||
/*
|
||||
* Random float in range [0,1)
|
||||
*/
|
||||
float SDL_rand_float(void)
|
||||
{
|
||||
return (SDL_rand() >> (32-24)) * 0x1p-24f;
|
||||
|
||||
Reference in New Issue
Block a user