Skip to content

Commit

Permalink
Updated tests to SDL_rand_n()
Browse files Browse the repository at this point in the history
  • Loading branch information
JKaniarz committed Jun 19, 2024
1 parent dc0ec6e commit 608e61e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
20 changes: 10 additions & 10 deletions test/testdraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ static void DrawPoints(SDL_Renderer *renderer)
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
(Uint8)current_color, (Uint8)current_alpha);

x = (float)(SDL_rand() % viewport.w);
y = (float)(SDL_rand() % viewport.h);
x = (float)(SDL_rand_n(viewport.w));
y = (float)(SDL_rand_n(viewport.h));
SDL_RenderPoint(renderer, x, y);
}
}
Expand Down Expand Up @@ -120,10 +120,10 @@ static void DrawLines(SDL_Renderer *renderer)
SDL_RenderLine(renderer, 0.0f, (float)(viewport.h / 2), (float)(viewport.w - 1), (float)(viewport.h / 2));
SDL_RenderLine(renderer, (float)(viewport.w / 2), 0.0f, (float)(viewport.w / 2), (float)(viewport.h - 1));
} else {
x1 = (float)((SDL_rand() % (viewport.w * 2)) - viewport.w);
x2 = (float)((SDL_rand() % (viewport.w * 2)) - viewport.w);
y1 = (float)((SDL_rand() % (viewport.h * 2)) - viewport.h);
y2 = (float)((SDL_rand() % (viewport.h * 2)) - viewport.h);
x1 = (float)((SDL_rand_n((viewport.w * 2))) - viewport.w);
x2 = (float)((SDL_rand_n((viewport.w * 2))) - viewport.w);
y1 = (float)((SDL_rand_n((viewport.h * 2))) - viewport.h);
y2 = (float)((SDL_rand_n((viewport.h * 2))) - viewport.h);
SDL_RenderLine(renderer, x1, y1, x2, y2);
}
}
Expand Down Expand Up @@ -165,10 +165,10 @@ static void DrawRects(SDL_Renderer *renderer)
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
(Uint8)current_color, (Uint8)current_alpha);

rect.w = (float)(SDL_rand() % (viewport.h / 2));
rect.h = (float)(SDL_rand() % (viewport.h / 2));
rect.x = (float)((SDL_rand() % (viewport.w * 2) - viewport.w) - (rect.w / 2));
rect.y = (float)((SDL_rand() % (viewport.h * 2) - viewport.h) - (rect.h / 2));
rect.w = (float)(SDL_rand_n((viewport.h / 2)));
rect.h = (float)(SDL_rand_n((viewport.h / 2)));
rect.x = (float)((SDL_rand_n((viewport.w * 2)) - viewport.w) - (rect.w / 2));
rect.y = (float)((SDL_rand_n((viewport.h * 2)) - viewport.h) - (rect.h / 2));
SDL_RenderFillRect(renderer, &rect);
}
}
Expand Down
20 changes: 10 additions & 10 deletions test/testintersections.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ static void DrawPoints(SDL_Renderer *renderer)
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
(Uint8)current_color, (Uint8)current_alpha);

x = (float)(SDL_rand() % viewport.w);
y = (float)(SDL_rand() % viewport.h);
x = (float)(SDL_rand_n(viewport.w));
y = (float)(SDL_rand_n(viewport.h));
SDL_RenderPoint(renderer, x, y);
}
}
Expand Down Expand Up @@ -231,21 +231,21 @@ static void loop(void *arg)
num_lines = 0;
} else {
add_line(
(float)(SDL_rand() % 640),
(float)(SDL_rand() % 480),
(float)(SDL_rand() % 640),
(float)(SDL_rand() % 480));
(float)(SDL_rand_n(640)),
(float)(SDL_rand_n(480)),
(float)(SDL_rand_n(640)),
(float)(SDL_rand_n(480)));
}
break;
case 'r':
if (event.key.keysym.mod & SDL_KMOD_SHIFT) {
num_rects = 0;
} else {
add_rect(
(float)(SDL_rand() % 640),
(float)(SDL_rand() % 480),
(float)(SDL_rand() % 640),
(float)(SDL_rand() % 480));
(float)(SDL_rand_n(640)),
(float)(SDL_rand_n(480)),
(float)(SDL_rand_n(640)),
(float)(SDL_rand_n(480)));
}
break;
default:
Expand Down
8 changes: 4 additions & 4 deletions test/testnative.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ int main(int argc, char *argv[])
quit(2);
}
for (i = 0; i < NUM_SPRITES; ++i) {
positions[i].x = (float)(SDL_rand() % (window_w - (int)sprite_w));
positions[i].y = (float)(SDL_rand() % (window_h - (int)sprite_h));
positions[i].x = (float)(SDL_rand_n((window_w - (int)sprite_w)));
positions[i].y = (float)(SDL_rand_n((window_h - (int)sprite_h)));
positions[i].w = sprite_w;
positions[i].h = 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)((SDL_rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED);
velocities[i].y = (float)((SDL_rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED);
velocities[i].x = (float)((SDL_rand_n((MAX_SPEED * 2 + 1))) - MAX_SPEED);
velocities[i].y = (float)((SDL_rand_n((MAX_SPEED * 2 + 1))) - MAX_SPEED);
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/testspriteminimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ int main(int argc, char *argv[])

/* Initialize the sprite positions */
for (i = 0; i < NUM_SPRITES; ++i) {
positions[i].x = (float)(SDL_rand() % (WINDOW_WIDTH - sprite_w));
positions[i].y = (float)(SDL_rand() % (WINDOW_HEIGHT - sprite_h));
positions[i].x = (float)(SDL_rand_n((WINDOW_WIDTH - sprite_w)));
positions[i].y = (float)(SDL_rand_n((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)((SDL_rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED);
velocities[i].y = (float)((SDL_rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED);
velocities[i].x = (float)((SDL_rand_n((MAX_SPEED * 2 + 1))) - MAX_SPEED);
velocities[i].y = (float)((SDL_rand_n((MAX_SPEED * 2 + 1))) - MAX_SPEED);
}
}

Expand Down

0 comments on commit 608e61e

Please sign in to comment.