mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-21 11:31:51 -05:00
Move pseudo RNG seeding to start of application
Also switched to qrand() in place of rand() where possible as it is thread safe. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@5716 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
5e2507e179
commit
5e3ec0e891
@ -32,14 +32,13 @@ Modulator::Modulator (unsigned frameRate, unsigned periodLengthInSeconds,
|
||||
, m_phi {0.0}
|
||||
, m_toneSpacing {0.0}
|
||||
, m_fSpread {0.0}
|
||||
, m_itone0 {0}
|
||||
, m_frameRate {frameRate}
|
||||
, m_period {periodLengthInSeconds}
|
||||
, m_state {Idle}
|
||||
, m_tuning {false}
|
||||
, m_cwLevel {false}
|
||||
{
|
||||
qsrand (QDateTime::currentMSecsSinceEpoch()); // Initialize random seed
|
||||
m_itone0=0;
|
||||
}
|
||||
|
||||
void Modulator::start (unsigned symbolsLength, double framesPerSymbol,
|
||||
@ -232,8 +231,8 @@ qint64 Modulator::readData (char * data, qint64 maxSize)
|
||||
|
||||
int j=m_ic/480;
|
||||
if(m_fSpread>0.0 and j!=j0) {
|
||||
float x1=(float)rand()/RAND_MAX;
|
||||
float x2=(float)rand()/RAND_MAX;
|
||||
float x1=(float)qrand()/RAND_MAX;
|
||||
float x2=(float)qrand()/RAND_MAX;
|
||||
toneFrequency = toneFrequency0 + 0.5*m_fSpread*(x1+x2-1.0);
|
||||
m_dphi = m_twoPi * toneFrequency / m_frameRate;
|
||||
j0=j;
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <QList>
|
||||
#include <QSet>
|
||||
#include <QtWidgets>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "SettingsGroup.hpp"
|
||||
#include "Configuration.hpp"
|
||||
@ -119,12 +118,6 @@ Dialog::Dialog (QSettings * settings, Configuration const * configuration, BandL
|
||||
main_layout->addLayout (bottom_layout);
|
||||
|
||||
setLayout (main_layout);
|
||||
|
||||
//init random seed for random number generator used in tx scheduler
|
||||
struct timeval time;
|
||||
gettimeofday(&time,NULL);
|
||||
srand((time.tv_sec*1000)+(time.tv_usec/1000));
|
||||
|
||||
}
|
||||
|
||||
Dialog::~Dialog ()
|
||||
|
@ -145,8 +145,8 @@ float gran()
|
||||
* that are inside the unit circle
|
||||
*/
|
||||
do {
|
||||
v1 = 2.0 * (float)rand() / RAND_MAX - 1;
|
||||
v2 = 2.0 * (float)rand() / RAND_MAX - 1;
|
||||
v1 = 2.0 * (float)qrand() / RAND_MAX - 1;
|
||||
v2 = 2.0 * (float)qrand() / RAND_MAX - 1;
|
||||
rsq = v1*v1 + v2*v2;
|
||||
} while(rsq >= 1.0 || rsq == 0.0);
|
||||
fac = sqrt(-2.0*log(rsq)/rsq);
|
||||
|
13
main.cpp
13
main.cpp
@ -5,6 +5,7 @@
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QApplication>
|
||||
#include <QRegularExpression>
|
||||
#include <QObject>
|
||||
@ -28,6 +29,18 @@
|
||||
#include "TraceFile.hpp"
|
||||
#include "mainwindow.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct RNGSetup
|
||||
{
|
||||
RNGSetup ()
|
||||
{
|
||||
// one time seed of pseudo RNGs from current time
|
||||
auto seed = QDateTime::currentMSecsSinceEpoch ();
|
||||
qsrand (seed); // this is good for rand() as well
|
||||
}
|
||||
} seeding;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -4009,7 +4009,7 @@ void MainWindow::p1ReadFromStdout() //p1readFromStdout
|
||||
m_nWSPRdecodes=0;
|
||||
ui->DecodeButton->setChecked (false);
|
||||
if(m_uploadSpots) {
|
||||
float x=rand()/((double)RAND_MAX + 1.0);
|
||||
float x=qrand()/((double)RAND_MAX + 1.0);
|
||||
int msdelay=20000*x;
|
||||
uploadTimer->start(msdelay); //Upload delay
|
||||
} else {
|
||||
|
@ -38,7 +38,6 @@ PSK_Reporter::PSK_Reporter(MessageClient * message_client, QObject *parent) :
|
||||
"00960004"; // Report time
|
||||
|
||||
|
||||
qsrand(QDateTime::currentDateTime().toTime_t());
|
||||
m_randomId_h = QString("%1").arg(qrand(),8,16,QChar('0'));
|
||||
|
||||
QHostInfo::lookupHost("report.pskreporter.info", this, SLOT(dnsLookupResult(QHostInfo)));
|
||||
|
Loading…
Reference in New Issue
Block a user