void MainWindow::on_actionRandomGeneration_triggered() { on_actionClear_triggered(); isSelectMannually = false; RandomPointsDialog * dialog = new RandomPointsDialog(this); dialog->exec(); QTime t; t.start(); std::random_device rd; std::mt19937 gen; gen.seed(rd()); for(int i = 0; i < dialog->getPointsNumber(); i++) { std::uniform_int_distribution<int> randx(1, this->width() / 2 - 2); std::uniform_int_distribution<int> randy(100, this->height() - 2); // 100 in order to avoid paint on toolbar points.append(QPoint(randx(gen), randy(gen))); } qDebug()<<"random time: "<<t.elapsed() / 1000.0; update(); isRandomized = true; }
int _tmain (int argc, LPTSTR argv []) { DWORD nRec, i; FILE *fp; DWORD iR; FILETIME fileTime; /* Times to seed random #s. */ SYSTEMTIME sysTime; TCHAR buffer [256]; if (argc < 3) ReportError (_T("Uasge: randfile nrec file"), 1, FALSE); nRec = _ttoi (argv [1]); if (_tfopen_s (&fp, argv [2], _T("wb")) != 0) ReportError (_T ("Failed opening output."), 2, TRUE); GetSystemTime (&sysTime); SystemTimeToFileTime (&sysTime, &fileTime); srandx (fileTime.dwLowDateTime); for (i = 0; i < nRec; i++) { iR = randx (); /* 62 characters, CR, LF */ _stprintf_s (buffer, sizeof(buffer), _T("%08x. Record Number: %08d.abcdefghijklmnopqrstuvwxyz x"), iR, i); buffer[62] = CR; buffer[63] = LF; // _fseeki64 (fp, ((__int64)64)*i, SEEK_SET); /* Assure that an extra null character is not inserted */ /* Not needed */ fwrite (buffer, 64, sizeof(TCHAR), fp); /* 64 characters, including CR, LF, but not EOL */ } fclose (fp); return 0; }