mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +00:00
Minesweeper: Use AK::get_random_uniform() instead of rand()
This commit is contained in:
parent
d3d170851d
commit
0de35db0f1
1 changed files with 2 additions and 3 deletions
|
@ -7,13 +7,13 @@
|
|||
#include "Field.h"
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/Queue.h>
|
||||
#include <AK/Random.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <time.h>
|
||||
|
||||
class SquareButton final : public GUI::Button {
|
||||
C_OBJECT(SquareButton);
|
||||
|
@ -111,7 +111,6 @@ Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_b
|
|||
, m_time_label(time_label)
|
||||
, m_on_size_changed(move(on_size_changed))
|
||||
{
|
||||
srand(time(nullptr));
|
||||
m_timer = add<Core::Timer>();
|
||||
m_timer->on_timeout = [this] {
|
||||
++m_time_elapsed;
|
||||
|
@ -216,7 +215,7 @@ void Field::reset()
|
|||
|
||||
HashTable<int> mines;
|
||||
while (mines.size() != m_mine_count) {
|
||||
int location = rand() % (rows() * columns());
|
||||
int location = get_random_uniform(rows() * columns());
|
||||
if (!mines.contains(location))
|
||||
mines.set(location);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue