Added SDL_srand(), SDL_rand(), and SDL_rand_r() (thanks @JKaniarz!)
These are simple random functions that should not be used for serious random number generation. Fixes https://github.com/libsdl-org/SDL/issues/4968
This commit is contained in:
@@ -10,9 +10,6 @@
|
||||
freely.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <wayland-client.h>
|
||||
#include <xdg-shell-client-protocol.h>
|
||||
@@ -99,17 +96,16 @@ static int InitSprites(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
for (int i = 0; i < NUM_SPRITES; ++i) {
|
||||
positions[i].x = (float)(rand() % (WINDOW_WIDTH - sprite_w));
|
||||
positions[i].y = (float)(rand() % (WINDOW_HEIGHT - sprite_h));
|
||||
positions[i].x = (float)(SDL_rand() % (WINDOW_WIDTH - sprite_w));
|
||||
positions[i].y = (float)(SDL_rand() % (WINDOW_HEIGHT - sprite_h));
|
||||
positions[i].w = (float)sprite_w;
|
||||
positions[i].h = (float)sprite_h;
|
||||
velocities[i].x = 0.0f;
|
||||
velocities[i].y = 0.0f;
|
||||
while (velocities[i].x == 0.f && velocities[i].y == 0.f) {
|
||||
velocities[i].x = (float)((rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED);
|
||||
velocities[i].y = (float)((rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED);
|
||||
velocities[i].x = (float)((SDL_rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED);
|
||||
velocities[i].y = (float)((SDL_rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user