1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 02:47:34 +00:00

Userland: Replace arc4random() with get_random<u32>()

This commit is contained in:
Jean-Baptiste Boric 2021-05-14 17:27:38 +02:00 committed by Andreas Kling
parent 5a0468c21f
commit 090936e424
8 changed files with 19 additions and 12 deletions

View file

@ -6,6 +6,7 @@
#include "Game.h"
#include "LevelSelectDialog.h"
#include <AK/Random.h>
#include <LibGUI/Application.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h>
@ -191,11 +192,11 @@ void Game::reset_ball()
{
int position_x_min = (game_width / 2) - 50;
int position_x_max = (game_width / 2) + 50;
int position_x = arc4random() % (position_x_max - position_x_min + 1) + position_x_min;
int position_x = get_random<u32>() % (position_x_max - position_x_min + 1) + position_x_min;
int position_y = 200;
int velocity_x = arc4random() % 3 + 1;
int velocity_x = get_random<u32>() % 3 + 1;
int velocity_y = 3 + (3 - velocity_x);
if (arc4random() % 2)
if (get_random<u32>() % 2)
velocity_x = velocity_x * -1;
m_ball = {};

View file

@ -6,6 +6,7 @@
#include "ChessWidget.h"
#include "PromotionDialog.h"
#include <AK/Random.h>
#include <AK/String.h>
#include <LibCore/DateTime.h>
#include <LibCore/File.h>
@ -382,7 +383,7 @@ void ChessWidget::reset()
m_playback_move_number = 0;
m_board_playback = Chess::Board();
m_board = Chess::Board();
m_side = (arc4random() % 2) ? Chess::Color::White : Chess::Color::Black;
m_side = (get_random<u32>() % 2) ? Chess::Color::White : Chess::Color::Black;
m_drag_enabled = true;
input_engine_move();
update();

View file

@ -5,6 +5,7 @@
*/
#include "Game.h"
#include <AK/Random.h>
#include <LibGUI/Painter.h>
#include <stdlib.h>
#include <time.h>
@ -30,7 +31,7 @@ void Game::seed_universe()
{
for (int y = 0; y < m_rows; y++) {
for (int x = 0; x < m_columns; x++) {
m_universe[y][x] = (arc4random() % 2) ? 1 : 0;
m_universe[y][x] = (get_random<u32>() % 2) ? 1 : 0;
}
}
}

View file

@ -5,6 +5,7 @@
*/
#include "Game.h"
#include <AK/Random.h>
namespace Pong {
@ -100,11 +101,11 @@ void Game::reset_ball(int serve_to_player)
{
int position_y_min = (game_width / 2) - 50;
int position_y_max = (game_width / 2) + 50;
int position_y = arc4random() % (position_y_max - position_y_min + 1) + position_y_min;
int position_y = get_random<u32>() % (position_y_max - position_y_min + 1) + position_y_min;
int position_x = (game_height / 2);
int velocity_y = arc4random() % 3 + 1;
int velocity_y = get_random<u32>() % 3 + 1;
int velocity_x = 5 + (5 - velocity_y);
if (arc4random() % 2)
if (get_random<u32>() % 2)
velocity_y = velocity_y * -1;
if (serve_to_player == 2)
velocity_x = velocity_x * -1;