Permalink
Browse files

Made the random seeds in the UI more random

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 35dc020f8aa5135c6cea6b656830d1fe8d935d19
Showing with 18 additions and 1 deletion.
  1. +5 −0 common/mt19937-64.c
  2. +2 −0 common/mt64.h
  3. +1 −0 ui/main-window.cpp
  4. +9 −1 ui/widgets.cpp
  5. +1 −0 ui/widgets.h
@@ -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);
@@ -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();
@@ -199,6 +199,7 @@ void MainWindow::handleButton()
"the ROM could not be created.");
}
this->saveConfig();
this->seed->random();
}
bool MainWindow::saveConfig()
@@ -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) :
@@ -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;
@@ -92,6 +92,7 @@ class SeedEntry : public ButtonEntry {
typedef ButtonEntry super;
SeedEntry(QWidget *parent = 0);
uint64_t getSeed();
void random();
private slots:
void handleButton();

0 comments on commit 35dc020

Please sign in to comment.