Changeset fc9f661ded in tspsg for src


Ignore:
Timestamp:
Oct 19, 2007, 4:22:33 AM (17 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
67e53c96d7
Parents:
95eca626aa
Message:

Fixed random number generation algorithm (didn't work at all in linux).

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/mainwindow.cpp

    r95eca626aa rfc9f661ded  
    2525#include "mainwindow.h"
    2626
    27 // TODO: Saving window state on close
     27// TODO: Saving window state on close.
    2828
    2929MainWindow::MainWindow(QWidget *parent)
     
    4040    rect.moveCenter(QApplication::desktop()->screenGeometry(QApplication::desktop()->primaryScreen()).center());
    4141        setGeometry(rect);
     42        qsrand(QDateTime().currentDateTime().toTime_t());
    4243        PrepareTable();
     44}
     45
     46int MainWindow::rand(int min, int max)
     47{
     48        return min + (int)(((float)qrand() / RAND_MAX) * max);
    4349}
    4450
     
    5662                                item->setFlags(item->flags() ^ Qt::ItemIsEditable);
    5763                        } else {
    58                                 item = new QTableWidgetItem(QVariant(randMin + qrand() * randMax / RAND_MAX).toString());
     64                                item = new QTableWidgetItem(QVariant(rand(randMin,randMax)).toString());
    5965QFont font = item->font();
    6066                                font.setBold(true);
     
    8995                tableTask->setItem(spinCities->value() - 1,spinCities->value() - 1,item);
    9096                for (int k = 0; k < spinCities->value() - 1; k++) {
    91                         item = new QTableWidgetItem(QVariant(randMin + qrand() * randMax / RAND_MAX).toString());
     97                        item = new QTableWidgetItem(QVariant(rand(randMin, randMax)).toString());
    9298QFont font = item->font();
    9399                        font.setBold(true);
    94100                        item->setFont(font);
    95101                        tableTask->setItem(k,spinCities->value() - 1,item);
    96                         item = new QTableWidgetItem(QVariant(randMin + qrand() * randMax / RAND_MAX).toString());
     102                        item = new QTableWidgetItem(QVariant(rand(randMin, randMax)).toString());
    97103                        font = item->font();
    98104                        font.setBold(true);
     
    119125                for (int x = 0; x < spinCities->value(); x++)
    120126                        if (x != y)
    121                                 tableTask->item(x,y)->setText(QVariant(randMin + qrand() * randMax / RAND_MAX).toString());
     127                                tableTask->item(x,y)->setText(QVariant(rand(randMin, randMax)).toString());
    122128}
    123129
  • src/mainwindow.h

    r95eca626aa rfc9f661ded  
    4141private:
    4242        void PrepareTable();
     43        int rand(int, int);
    4344        int randMin;
    4445        int randMax;
Note: See TracChangeset for help on using the changeset viewer.