Skip to content

Commit

Permalink
Made the random seeds in the UI more random
Browse files Browse the repository at this point in the history
The random seeds in the UI were not so random on Windows.
Changed the UI such that a new random seed is chosen after generating a ROM.
  • Loading branch information
mcgrew committed Jan 20, 2018
1 parent cf80ee0 commit 35dc020
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions common/mt19937-64.c
Expand Up @@ -129,6 +129,11 @@ uint64_t mt_rand(uint64_t min, uint64_t max)
return min + (genrand64_int64() % (max - min + 1));
}

uint64_t mt_rand64()
{
return genrand64_int64();
}

double mt_rand_double()
{
return (genrand64_int64() >> 11) * (1.0/9007199254740992.0);
Expand Down
2 changes: 2 additions & 0 deletions common/mt64.h
Expand Up @@ -67,6 +67,8 @@ void mt_init(uint64_t seed);

uint64_t mt_rand(uint64_t min, uint64_t max);

uint64_t mt_rand64();

int mt_rand_bool();

double mt_rand_double();
Expand Down
1 change: 1 addition & 0 deletions ui/main-window.cpp
Expand Up @@ -199,6 +199,7 @@ void MainWindow::handleButton()
"the ROM could not be created.");
}
this->saveConfig();
this->seed->random();
}

bool MainWindow::saveConfig()
Expand Down
10 changes: 9 additions & 1 deletion ui/widgets.cpp
Expand Up @@ -8,6 +8,7 @@
#include <cinttypes>

#include "dwr.h"
#include "mt64.h"
#include "widgets.h"

CheckBox::CheckBox(const char flag, const QString &text, QWidget *parent) :
Expand Down Expand Up @@ -142,16 +143,23 @@ SeedEntry::SeedEntry(QWidget *parent) : ButtonEntry(parent)
this->handleButton();
}

void SeedEntry::handleButton()
void SeedEntry::random()
{
uint64_t seed;
char seedString[21];
srand(time(NULL));
seed = ((uint64_t)rand() << 32) | ((uint64_t)rand() & 0xffffffffL);
mt_init(seed);
seed = mt_rand64();
snprintf(seedString, 21, "%" PRIu64, seed);
this->textBox->setText(QString(seedString));
}

void SeedEntry::handleButton()
{
this->random();
}

uint64_t SeedEntry::getSeed()
{
uint64_t seed;
Expand Down
1 change: 1 addition & 0 deletions ui/widgets.h
Expand Up @@ -92,6 +92,7 @@ class SeedEntry : public ButtonEntry {
typedef ButtonEntry super;
SeedEntry(QWidget *parent = 0);
uint64_t getSeed();
void random();

private slots:
void handleButton();
Expand Down

0 comments on commit 35dc020

Please sign in to comment.