Change almost all other uses of qrand() to QRandomGenerator
The vast majority is actually switched to QRandomGenerator::bounded(), which gives a mostly uniform distribution over the [0, bound) range. There are very few floating point cases left, as many of those that did use floating point did not need to, after all. (I did leave some that were too ugly for me to understand) This commit also found a couple of calls to rand() instead of qrand(). This commit does not include changes to SSL code that continues to use qrand() (job for someone else): src/network/ssl/qsslkey_qt.cpp src/network/ssl/qsslsocket_mac.cpp tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp Change-Id: Icd0e0d4b27cb4e5eb892fffd14b5285d43f4afbf Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
59c5f7bd9d
commit
19b0ce5daa
@ -106,7 +106,7 @@ void Server::sendFortune()
|
|||||||
QByteArray block;
|
QByteArray block;
|
||||||
QDataStream out(&block, QIODevice::WriteOnly);
|
QDataStream out(&block, QIODevice::WriteOnly);
|
||||||
out.setVersion(QDataStream::Qt_5_10);
|
out.setVersion(QDataStream::Qt_5_10);
|
||||||
const int fortuneIndex = QRandomGenerator::bounded(0, fortunes.size());
|
const int fortuneIndex = QRandomGenerator::global()->bounded(0, fortunes.size());
|
||||||
const QString &message = fortunes.at(fortuneIndex);
|
const QString &message = fortunes.at(fortuneIndex);
|
||||||
out << quint32(message.size());
|
out << quint32(message.size());
|
||||||
out << message;
|
out << message;
|
||||||
|
@ -72,7 +72,7 @@ void Game::newGame()
|
|||||||
mPlayer = Character();
|
mPlayer = Character();
|
||||||
mPlayer.setName(QStringLiteral("Hero"));
|
mPlayer.setName(QStringLiteral("Hero"));
|
||||||
mPlayer.setClassType(Character::Archer);
|
mPlayer.setClassType(Character::Archer);
|
||||||
mPlayer.setLevel(QRandomGenerator::bounded(15, 21));
|
mPlayer.setLevel(QRandomGenerator::global()->bounded(15, 21));
|
||||||
|
|
||||||
mLevels.clear();
|
mLevels.clear();
|
||||||
mLevels.reserve(2);
|
mLevels.reserve(2);
|
||||||
@ -81,10 +81,10 @@ void Game::newGame()
|
|||||||
QVector<Character> villageNpcs;
|
QVector<Character> villageNpcs;
|
||||||
villageNpcs.reserve(2);
|
villageNpcs.reserve(2);
|
||||||
villageNpcs.append(Character(QStringLiteral("Barry the Blacksmith"),
|
villageNpcs.append(Character(QStringLiteral("Barry the Blacksmith"),
|
||||||
QRandomGenerator::bounded(8, 11),
|
QRandomGenerator::global()->bounded(8, 11),
|
||||||
Character::Warrior));
|
Character::Warrior));
|
||||||
villageNpcs.append(Character(QStringLiteral("Terry the Trader"),
|
villageNpcs.append(Character(QStringLiteral("Terry the Trader"),
|
||||||
QRandomGenerator::bounded(6, 8),
|
QRandomGenerator::global()->bounded(6, 8),
|
||||||
Character::Warrior));
|
Character::Warrior));
|
||||||
village.setNpcs(villageNpcs);
|
village.setNpcs(villageNpcs);
|
||||||
mLevels.append(village);
|
mLevels.append(village);
|
||||||
@ -93,13 +93,13 @@ void Game::newGame()
|
|||||||
QVector<Character> dungeonNpcs;
|
QVector<Character> dungeonNpcs;
|
||||||
dungeonNpcs.reserve(3);
|
dungeonNpcs.reserve(3);
|
||||||
dungeonNpcs.append(Character(QStringLiteral("Eric the Evil"),
|
dungeonNpcs.append(Character(QStringLiteral("Eric the Evil"),
|
||||||
QRandomGenerator::bounded(18, 26),
|
QRandomGenerator::global()->bounded(18, 26),
|
||||||
Character::Mage));
|
Character::Mage));
|
||||||
dungeonNpcs.append(Character(QStringLiteral("Eric's Left Minion"),
|
dungeonNpcs.append(Character(QStringLiteral("Eric's Left Minion"),
|
||||||
QRandomGenerator::bounded(5, 7),
|
QRandomGenerator::global()->bounded(5, 7),
|
||||||
Character::Warrior));
|
Character::Warrior));
|
||||||
dungeonNpcs.append(Character(QStringLiteral("Eric's Right Minion"),
|
dungeonNpcs.append(Character(QStringLiteral("Eric's Right Minion"),
|
||||||
QRandomGenerator::bounded(4, 9),
|
QRandomGenerator::global()->bounded(4, 9),
|
||||||
Character::Warrior));
|
Character::Warrior));
|
||||||
dungeon.setNpcs(dungeonNpcs);
|
dungeon.setNpcs(dungeonNpcs);
|
||||||
mLevels.append(dungeon);
|
mLevels.append(dungeon);
|
||||||
|
@ -126,7 +126,6 @@ int main(int argc, char *argv[])
|
|||||||
//! [main start] //! [register meta-type for queued communications]
|
//! [main start] //! [register meta-type for queued communications]
|
||||||
qRegisterMetaType<Block>();
|
qRegisterMetaType<Block>();
|
||||||
//! [register meta-type for queued communications]
|
//! [register meta-type for queued communications]
|
||||||
qsrand(QTime::currentTime().elapsed());
|
|
||||||
|
|
||||||
Window window;
|
Window window;
|
||||||
window.show();
|
window.show();
|
||||||
|
@ -50,6 +50,8 @@
|
|||||||
|
|
||||||
#include "renderthread.h"
|
#include "renderthread.h"
|
||||||
|
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
RenderThread::RenderThread(QObject *parent)
|
RenderThread::RenderThread(QObject *parent)
|
||||||
: QThread(parent)
|
: QThread(parent)
|
||||||
{
|
{
|
||||||
@ -82,9 +84,9 @@ void RenderThread::run()
|
|||||||
for (int s = size; s > 0; --s) {
|
for (int s = size; s > 0; --s) {
|
||||||
for (int c = 0; c < 400; ++c) {
|
for (int c = 0; c < 400; ++c) {
|
||||||
//![processing the image (start)]
|
//![processing the image (start)]
|
||||||
int x1 = qMax(0, (qrand() % m_image.width()) - s/2);
|
int x1 = qMax(0, QRandomGenerator::global()->bounded(m_image.width()) - s/2);
|
||||||
int x2 = qMin(x1 + s/2 + 1, m_image.width());
|
int x2 = qMin(x1 + s/2 + 1, m_image.width());
|
||||||
int y1 = qMax(0, (qrand() % m_image.height()) - s/2);
|
int y1 = qMax(0, QRandomGenerator::global()->bounded(m_image.height()) - s/2);
|
||||||
int y2 = qMin(y1 + s/2 + 1, m_image.height());
|
int y2 = qMin(y1 + s/2 + 1, m_image.height());
|
||||||
int n = 0;
|
int n = 0;
|
||||||
int red = 0;
|
int red = 0;
|
||||||
|
@ -70,10 +70,9 @@ class Producer : public QThread
|
|||||||
public:
|
public:
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
|
||||||
for (int i = 0; i < DataSize; ++i) {
|
for (int i = 0; i < DataSize; ++i) {
|
||||||
freeBytes.acquire();
|
freeBytes.acquire();
|
||||||
buffer[i % BufferSize] = "ACGT"[(int)qrand() % 4];
|
buffer[i % BufferSize] = "ACGT"[QRandomGenerator::global()->bounded(4)];
|
||||||
usedBytes.release();
|
usedBytes.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,15 +76,13 @@ public:
|
|||||||
|
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
|
||||||
|
|
||||||
for (int i = 0; i < DataSize; ++i) {
|
for (int i = 0; i < DataSize; ++i) {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
if (numUsedBytes == BufferSize)
|
if (numUsedBytes == BufferSize)
|
||||||
bufferNotFull.wait(&mutex);
|
bufferNotFull.wait(&mutex);
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
|
|
||||||
buffer[i % BufferSize] = "ACGT"[(int)qrand() % 4];
|
buffer[i % BufferSize] = "ACGT"[QRandomGenerator::global()->bounded(4)];
|
||||||
|
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
++numUsedBytes;
|
++numUsedBytes;
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "randomlistmodel.h"
|
#include "randomlistmodel.h"
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static const int bufferSize(500);
|
static const int bufferSize(500);
|
||||||
@ -101,6 +102,6 @@ void RandomListModel::cacheRows(int from, int to) const
|
|||||||
//![1]
|
//![1]
|
||||||
QString RandomListModel::fetchRow(int position) const
|
QString RandomListModel::fetchRow(int position) const
|
||||||
{
|
{
|
||||||
return QString::number(rand() % ++position);
|
return QString::number(QRandomGenerator::global()->bounded(++position));
|
||||||
}
|
}
|
||||||
//![1]
|
//![1]
|
||||||
|
@ -72,7 +72,7 @@ static QStringList colorPairs(int max)
|
|||||||
// randomize it
|
// randomize it
|
||||||
colors.clear();
|
colors.clear();
|
||||||
while (combinedColors.count()) {
|
while (combinedColors.count()) {
|
||||||
int i = qrand() % combinedColors.count();
|
int i = QRandomGenerator::global()->bounded(combinedColors.count());
|
||||||
colors << combinedColors[i];
|
colors << combinedColors[i];
|
||||||
combinedColors.removeAt(i);
|
combinedColors.removeAt(i);
|
||||||
if (colors.count() == max)
|
if (colors.count() == max)
|
||||||
|
@ -182,7 +182,7 @@ void Server::sendFortune()
|
|||||||
QDataStream out(&block, QIODevice::WriteOnly);
|
QDataStream out(&block, QIODevice::WriteOnly);
|
||||||
out.setVersion(QDataStream::Qt_5_10);
|
out.setVersion(QDataStream::Qt_5_10);
|
||||||
|
|
||||||
out << fortunes[QRandomGenerator::bounded(fortunes.size())];
|
out << fortunes[QRandomGenerator::global()->bounded(fortunes.size())];
|
||||||
//! [4] //! [7]
|
//! [4] //! [7]
|
||||||
|
|
||||||
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
|
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
|
||||||
|
@ -51,6 +51,8 @@
|
|||||||
#include "fortuneserver.h"
|
#include "fortuneserver.h"
|
||||||
#include "fortunethread.h"
|
#include "fortunethread.h"
|
||||||
|
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
@ -70,7 +72,7 @@ FortuneServer::FortuneServer(QObject *parent)
|
|||||||
//! [1]
|
//! [1]
|
||||||
void FortuneServer::incomingConnection(qintptr socketDescriptor)
|
void FortuneServer::incomingConnection(qintptr socketDescriptor)
|
||||||
{
|
{
|
||||||
QString fortune = fortunes.at(qrand() % fortunes.size());
|
QString fortune = fortunes.at(QRandomGenerator::global()->bounded(fortunes.size()));
|
||||||
FortuneThread *thread = new FortuneThread(socketDescriptor, fortune, this);
|
FortuneThread *thread = new FortuneThread(socketDescriptor, fortune, this);
|
||||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||||
thread->start();
|
thread->start();
|
||||||
|
@ -60,6 +60,5 @@ int main(int argc, char *argv[])
|
|||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
Dialog dialog;
|
Dialog dialog;
|
||||||
dialog.show();
|
dialog.show();
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,6 @@
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
|
||||||
|
|
||||||
Q_INIT_RESOURCE(icons);
|
Q_INIT_RESOURCE(icons);
|
||||||
|
|
||||||
|
@ -692,7 +692,7 @@ void TorrentClient::connectToPeers()
|
|||||||
|
|
||||||
// Start as many connections as we can
|
// Start as many connections as we can
|
||||||
while (!weighedPeers.isEmpty() && ConnectionManager::instance()->canAddConnection()
|
while (!weighedPeers.isEmpty() && ConnectionManager::instance()->canAddConnection()
|
||||||
&& (qrand() % (ConnectionManager::instance()->maxConnections() / 2))) {
|
&& (QRandomGenerator::global()->bounded(ConnectionManager::instance()->maxConnections() / 2))) {
|
||||||
PeerWireClient *client = new PeerWireClient(ConnectionManager::instance()->clientId(), this);
|
PeerWireClient *client = new PeerWireClient(ConnectionManager::instance()->clientId(), this);
|
||||||
RateController::instance()->addSocket(client);
|
RateController::instance()->addSocket(client);
|
||||||
ConnectionManager::instance()->addConnection(client);
|
ConnectionManager::instance()->addConnection(client);
|
||||||
@ -701,7 +701,7 @@ void TorrentClient::connectToPeers()
|
|||||||
d->connections << client;
|
d->connections << client;
|
||||||
|
|
||||||
// Pick a random peer from the list of weighed peers.
|
// Pick a random peer from the list of weighed peers.
|
||||||
TorrentPeer *peer = weighedPeers.takeAt(qrand() % weighedPeers.size());
|
TorrentPeer *peer = weighedPeers.takeAt(QRandomGenerator::global()->bounded(weighedPeers.size()));
|
||||||
weighedPeers.removeAll(peer);
|
weighedPeers.removeAll(peer);
|
||||||
peer->connectStart = QDateTime::currentSecsSinceEpoch();
|
peer->connectStart = QDateTime::currentSecsSinceEpoch();
|
||||||
peer->lastVisited = peer->connectStart;
|
peer->lastVisited = peer->connectStart;
|
||||||
@ -1114,7 +1114,7 @@ void TorrentClient::scheduleUploads()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((client->peerWireState() & PeerWireClient::ChokingPeer) == 0) {
|
if ((client->peerWireState() & PeerWireClient::ChokingPeer) == 0) {
|
||||||
if ((qrand() % 10) == 0)
|
if ((QRandomGenerator::global()->bounded(10)) == 0)
|
||||||
client->abort();
|
client->abort();
|
||||||
else
|
else
|
||||||
client->chokePeer();
|
client->chokePeer();
|
||||||
@ -1128,7 +1128,7 @@ void TorrentClient::scheduleUploads()
|
|||||||
// random peer to allow it to compete for a position among the
|
// random peer to allow it to compete for a position among the
|
||||||
// downloaders. (This is known as an "optimistic unchoke".)
|
// downloaders. (This is known as an "optimistic unchoke".)
|
||||||
if (!allClients.isEmpty()) {
|
if (!allClients.isEmpty()) {
|
||||||
PeerWireClient *client = allClients[qrand() % allClients.size()];
|
PeerWireClient *client = allClients[QRandomGenerator::global()->bounded(allClients.size())];
|
||||||
if (client->peerWireState() & PeerWireClient::ChokingPeer)
|
if (client->peerWireState() & PeerWireClient::ChokingPeer)
|
||||||
client->unchokePeer();
|
client->unchokePeer();
|
||||||
}
|
}
|
||||||
@ -1189,7 +1189,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
|
|||||||
piece = d->payloads.value(client);
|
piece = d->payloads.value(client);
|
||||||
if (!piece) {
|
if (!piece) {
|
||||||
QList<TorrentPiece *> values = d->pendingPieces.values();
|
QList<TorrentPiece *> values = d->pendingPieces.values();
|
||||||
piece = values.value(qrand() % values.size());
|
piece = values.value(QRandomGenerator::global()->bounded(values.size()));
|
||||||
piece->inProgress = true;
|
piece->inProgress = true;
|
||||||
d->payloads.insert(client, piece);
|
d->payloads.insert(client, piece);
|
||||||
}
|
}
|
||||||
@ -1246,14 +1246,14 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
if (!partialPieces.isEmpty())
|
if (!partialPieces.isEmpty())
|
||||||
piece = partialPieces.value(qrand() % partialPieces.size());
|
piece = partialPieces.value(QRandomGenerator::global()->bounded(partialPieces.size()));
|
||||||
|
|
||||||
if (!piece) {
|
if (!piece) {
|
||||||
// Pick a random piece 3 out of 4 times; otherwise, pick either
|
// Pick a random piece 3 out of 4 times; otherwise, pick either
|
||||||
// one of the most common or the least common pieces available,
|
// one of the most common or the least common pieces available,
|
||||||
// depending on the state we're in.
|
// depending on the state we're in.
|
||||||
int pieceIndex = 0;
|
int pieceIndex = 0;
|
||||||
if (d->state == WarmingUp || (qrand() & 4) == 0) {
|
if (d->state == WarmingUp || (QRandomGenerator::global()->generate() & 4) == 0) {
|
||||||
int *occurrences = new int[d->pieceCount];
|
int *occurrences = new int[d->pieceCount];
|
||||||
memset(occurrences, 0, d->pieceCount * sizeof(int));
|
memset(occurrences, 0, d->pieceCount * sizeof(int));
|
||||||
|
|
||||||
@ -1293,7 +1293,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select one piece randomly
|
// Select one piece randomly
|
||||||
pieceIndex = piecesReadyForDownload.at(qrand() % piecesReadyForDownload.size());
|
pieceIndex = piecesReadyForDownload.at(QRandomGenerator::global()->bounded(piecesReadyForDownload.size()));
|
||||||
delete [] occurrences;
|
delete [] occurrences;
|
||||||
} else {
|
} else {
|
||||||
// Make up a list of available piece indices, and pick
|
// Make up a list of available piece indices, and pick
|
||||||
@ -1304,7 +1304,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
|
|||||||
if (incompletePiecesAvailableToClient.testBit(i))
|
if (incompletePiecesAvailableToClient.testBit(i))
|
||||||
values << i;
|
values << i;
|
||||||
}
|
}
|
||||||
pieceIndex = values.at(qrand() % values.size());
|
pieceIndex = values.at(QRandomGenerator::global()->bounded(values.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new TorrentPiece and fill in all initial
|
// Create a new TorrentPiece and fill in all initial
|
||||||
@ -1396,8 +1396,8 @@ int TorrentClient::requestBlocks(PeerWireClient *client, TorrentPiece *piece, in
|
|||||||
// speedup comes from an increased chance of receiving
|
// speedup comes from an increased chance of receiving
|
||||||
// different blocks from the different peers.
|
// different blocks from the different peers.
|
||||||
for (int i = 0; i < bits.size(); ++i) {
|
for (int i = 0; i < bits.size(); ++i) {
|
||||||
int a = qrand() % bits.size();
|
int a = QRandomGenerator::global()->bounded(bits.size());
|
||||||
int b = qrand() % bits.size();
|
int b = QRandomGenerator::global()->bounded(bits.size());
|
||||||
int tmp = bits[a];
|
int tmp = bits[a];
|
||||||
bits[a] = bits[b];
|
bits[a] = bits[b];
|
||||||
bits[b] = tmp;
|
bits[b] = tmp;
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
|
|
||||||
#include <QOpenGLContext>
|
#include <QOpenGLContext>
|
||||||
#include <QOpenGLFunctions>
|
#include <QOpenGLFunctions>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
Renderer::Renderer(const QSurfaceFormat &format, Renderer *share, QScreen *screen)
|
Renderer::Renderer(const QSurfaceFormat &format, Renderer *share, QScreen *screen)
|
||||||
@ -68,9 +69,9 @@ Renderer::Renderer(const QSurfaceFormat &format, Renderer *share, QScreen *scree
|
|||||||
m_context->create();
|
m_context->create();
|
||||||
|
|
||||||
m_backgroundColor = QColor::fromRgbF(0.1f, 0.1f, 0.2f, 1.0f);
|
m_backgroundColor = QColor::fromRgbF(0.1f, 0.1f, 0.2f, 1.0f);
|
||||||
m_backgroundColor.setRed(qrand() % 64);
|
m_backgroundColor.setRed(QRandomGenerator::global()->bounded(64));
|
||||||
m_backgroundColor.setGreen(qrand() % 128);
|
m_backgroundColor.setGreen(QRandomGenerator::global()->bounded(128));
|
||||||
m_backgroundColor.setBlue(qrand() % 256);
|
m_backgroundColor.setBlue(QRandomGenerator::global()->bounded(256));
|
||||||
}
|
}
|
||||||
|
|
||||||
HelloWindow::HelloWindow(const QSharedPointer<Renderer> &renderer, QScreen *screen)
|
HelloWindow::HelloWindow(const QSharedPointer<Renderer> &renderer, QScreen *screen)
|
||||||
|
@ -50,6 +50,8 @@
|
|||||||
|
|
||||||
#include "bubble.h"
|
#include "bubble.h"
|
||||||
|
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity)
|
Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity)
|
||||||
: position(position), vel(velocity), radius(radius)
|
: position(position), vel(velocity), radius(radius)
|
||||||
{
|
{
|
||||||
@ -80,10 +82,10 @@ void Bubble::drawBubble(QPainter *painter)
|
|||||||
|
|
||||||
QColor Bubble::randomColor()
|
QColor Bubble::randomColor()
|
||||||
{
|
{
|
||||||
int red = int(205 + 50.0*qrand()/(RAND_MAX+1.0));
|
int red = int(205 + QRandomGenerator::global()->bounded(50));
|
||||||
int green = int(205 + 50.0*qrand()/(RAND_MAX+1.0));
|
int green = int(205 + QRandomGenerator::global()->bounded(50));
|
||||||
int blue = int(205 + 50.0*qrand()/(RAND_MAX+1.0));
|
int blue = int(205 + QRandomGenerator::global()->bounded(50));
|
||||||
int alpha = int(91 + 100.0*qrand()/(RAND_MAX+1.0));
|
int alpha = int(91 + QRandomGenerator::global()->bounded(100));
|
||||||
|
|
||||||
return QColor(red, green, blue, alpha);
|
return QColor(red, green, blue, alpha);
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
#include "glwidget.h"
|
#include "glwidget.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@ -67,7 +68,6 @@ GLWidget::GLWidget(QWidget *parent)
|
|||||||
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
|
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
|
||||||
{
|
{
|
||||||
QTime midnight(0, 0, 0);
|
QTime midnight(0, 0, 0);
|
||||||
qsrand(midnight.secsTo(QTime::currentTime()));
|
|
||||||
|
|
||||||
logo = 0;
|
logo = 0;
|
||||||
xRot = 0;
|
xRot = 0;
|
||||||
@ -234,11 +234,11 @@ QSize GLWidget::sizeHint() const
|
|||||||
void GLWidget::createBubbles(int number)
|
void GLWidget::createBubbles(int number)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < number; ++i) {
|
for (int i = 0; i < number; ++i) {
|
||||||
QPointF position(width()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))),
|
QPointF position(width()*(0.1 + QRandomGenerator::global()->bounded(0.8)),
|
||||||
height()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))));
|
height()*(0.1 + QRandomGenerator::global()->bounded(0.8)));
|
||||||
qreal radius = qMin(width(), height())*(0.0125 + 0.0875*qrand()/(RAND_MAX+1.0));
|
qreal radius = qMin(width(), height())*(0.0125 + QRandomGenerator::global()->bounded(0.0875));
|
||||||
QPointF velocity(width()*0.0125*(-0.5 + qrand()/(RAND_MAX+1.0)),
|
QPointF velocity(width()*0.0125*(-0.5 + QRandomGenerator::global()->bounded(1.0)),
|
||||||
height()*0.0125*(-0.5 + qrand()/(RAND_MAX+1.0)));
|
height()*0.0125*(-0.5 + QRandomGenerator::global()->bounded(1.0)));
|
||||||
|
|
||||||
bubbles.append(new Bubble(position, radius, velocity));
|
bubbles.append(new Bubble(position, radius, velocity));
|
||||||
}
|
}
|
||||||
|
@ -109,10 +109,10 @@ void Bubble::drawBubble(QPainter *painter)
|
|||||||
|
|
||||||
QColor Bubble::randomColor()
|
QColor Bubble::randomColor()
|
||||||
{
|
{
|
||||||
int red = int(185 + 70.0*qrand()/(RAND_MAX+1.0));
|
int red = int(185 + QRandomGenerator::global()->bounded(70));
|
||||||
int green = int(185 + 70.0*qrand()/(RAND_MAX+1.0));
|
int green = int(185 + QRandomGenerator::global()->bounded(70));
|
||||||
int blue = int(205 + 50.0*qrand()/(RAND_MAX+1.0));
|
int blue = int(205 + QRandomGenerator::global()->bounded(50));
|
||||||
int alpha = int(91 + 100.0*qrand()/(RAND_MAX+1.0));
|
int alpha = int(91 + QRandomGenerator::global()->bounded(100));
|
||||||
|
|
||||||
return QColor(red, green, blue, alpha);
|
return QColor(red, green, blue, alpha);
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
#include <QPaintEngine>
|
#include <QPaintEngine>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QOpenGLTexture>
|
#include <QOpenGLTexture>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
@ -420,11 +421,11 @@ void GLWidget::paintGL()
|
|||||||
void GLWidget::createBubbles(int number)
|
void GLWidget::createBubbles(int number)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < number; ++i) {
|
for (int i = 0; i < number; ++i) {
|
||||||
QPointF position(width()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))),
|
QPointF position(width()*(0.1 + QRandomGenerator::global()->bounded(0.8)),
|
||||||
height()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))));
|
height()*(0.1 + QRandomGenerator::global()->bounded(0.8)));
|
||||||
qreal radius = qMin(width(), height())*(0.0175 + 0.0875*qrand()/(RAND_MAX+1.0));
|
qreal radius = qMin(width(), height())*(0.0175 + QRandomGenerator::global()->bounded(0.0875));
|
||||||
QPointF velocity(width()*0.0175*(-0.5 + qrand()/(RAND_MAX+1.0)),
|
QPointF velocity(width()*0.0175*(-0.5 + QRandomGenerator::global()->bounded(1.0)),
|
||||||
height()*0.0175*(-0.5 + qrand()/(RAND_MAX+1.0)));
|
height()*0.0175*(-0.5 + QRandomGenerator::global()->bounded(1.0)));
|
||||||
|
|
||||||
m_bubbles.append(new Bubble(position, radius, velocity));
|
m_bubbles.append(new Bubble(position, radius, velocity));
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,7 @@
|
|||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
|
|
||||||
@ -155,7 +156,9 @@ void MainWindow::addNew()
|
|||||||
{
|
{
|
||||||
if (m_nextY == 4)
|
if (m_nextY == 4)
|
||||||
return;
|
return;
|
||||||
GLWidget *w = new GLWidget(this, false, qRgb(qrand() % 256, qrand() % 256, qrand() % 256));
|
GLWidget *w = new GLWidget(this, false, qRgb(QRandomGenerator::global()->bounded(256),
|
||||||
|
QRandomGenerator::global()->bounded(256),
|
||||||
|
QRandomGenerator::global()->bounded(256)));
|
||||||
m_glWidgets << w;
|
m_glWidgets << w;
|
||||||
connect(m_timer, &QTimer::timeout, w, QOverload<>::of(&QWidget::update));
|
connect(m_timer, &QTimer::timeout, w, QOverload<>::of(&QWidget::update));
|
||||||
m_layout->addWidget(w, m_nextY, m_nextX, 1, 1);
|
m_layout->addWidget(w, m_nextY, m_nextX, 1, 1);
|
||||||
|
@ -61,7 +61,6 @@ static const int MouseCount = 7;
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
|
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
@ -70,9 +71,9 @@ static qreal normalizeAngle(qreal angle)
|
|||||||
//! [0]
|
//! [0]
|
||||||
Mouse::Mouse()
|
Mouse::Mouse()
|
||||||
: angle(0), speed(0), mouseEyeDirection(0),
|
: angle(0), speed(0), mouseEyeDirection(0),
|
||||||
color(qrand() % 256, qrand() % 256, qrand() % 256)
|
color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
|
||||||
{
|
{
|
||||||
setTransform(QTransform().rotate(qrand() % (360 * 16)), true);
|
setTransform(QTransform().rotate(QRandomGenerator::global()->bounded(360 * 16)), true);
|
||||||
startTimer(1000 / 33);
|
startTimer(1000 / 33);
|
||||||
}
|
}
|
||||||
//! [0]
|
//! [0]
|
||||||
@ -184,16 +185,16 @@ void Mouse::timerEvent(QTimerEvent *)
|
|||||||
|
|
||||||
// Add some random movement
|
// Add some random movement
|
||||||
//! [10]
|
//! [10]
|
||||||
if (dangerMice.size() > 1 && (qrand() % 10) == 0) {
|
if (dangerMice.size() > 1 && QRandomGenerator::global()->bounded(10) == 0) {
|
||||||
if (qrand() % 1)
|
if (QRandomGenerator::global()->bounded(1))
|
||||||
angle += (qrand() % 100) / 500.0;
|
angle += QRandomGenerator::global()->bounded(1 / 500.0);
|
||||||
else
|
else
|
||||||
angle -= (qrand() % 100) / 500.0;
|
angle -= QRandomGenerator::global()->bounded(1 / 500.0);
|
||||||
}
|
}
|
||||||
//! [10]
|
//! [10]
|
||||||
|
|
||||||
//! [11]
|
//! [11]
|
||||||
speed += (-50 + qrand() % 100) / 100.0;
|
speed += (-50 + QRandomGenerator::global()->bounded(100)) / 100.0;
|
||||||
|
|
||||||
qreal dx = ::sin(angle) * 10;
|
qreal dx = ::sin(angle) * 10;
|
||||||
mouseEyeDirection = (qAbs(dx / 5) < 1) ? 0 : dx / 5;
|
mouseEyeDirection = (qAbs(dx / 5) < 1) ? 0 : dx / 5;
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
|
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
#include <QtCore/qmath.h>
|
#include <QtCore/qmath.h>
|
||||||
|
#include <QtCore/qrandom.h>
|
||||||
#include <QtCore/qstate.h>
|
#include <QtCore/qstate.h>
|
||||||
|
|
||||||
class Pixmap : public QObject, public QGraphicsPixmapItem
|
class Pixmap : public QObject, public QGraphicsPixmapItem
|
||||||
@ -202,8 +203,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
// Random
|
// Random
|
||||||
randomState->assignProperty(item, "pos",
|
randomState->assignProperty(item, "pos",
|
||||||
QPointF(-250 + qrand() % 500,
|
QPointF(-250 + QRandomGenerator::global()->bounded(500),
|
||||||
-250 + qrand() % 500));
|
-250 + QRandomGenerator::global()->bounded(500)));
|
||||||
|
|
||||||
// Tiled
|
// Tiled
|
||||||
tiledState->assignProperty(item, "pos",
|
tiledState->assignProperty(item, "pos",
|
||||||
|
@ -125,7 +125,7 @@ public:
|
|||||||
void onEntry(QEvent *) override
|
void onEntry(QEvent *) override
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
while ((n = (qrand() % m_stateCount + 1)) == m_lastIndex)
|
while ((n = QRandomGenerator::global()->bounded(m_stateCount) + 1) == m_lastIndex)
|
||||||
{ }
|
{ }
|
||||||
m_lastIndex = n;
|
m_lastIndex = n;
|
||||||
machine()->postEvent(new StateSwitchEvent(n));
|
machine()->postEvent(new StateSwitchEvent(n));
|
||||||
@ -323,8 +323,6 @@ int main(int argc, char **argv)
|
|||||||
window.resize(300, 300);
|
window.resize(300, 300);
|
||||||
window.show();
|
window.show();
|
||||||
|
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,13 +91,12 @@ public:
|
|||||||
: QEventTransition(this, QEvent::Timer)
|
: QEventTransition(this, QEvent::Timer)
|
||||||
{
|
{
|
||||||
setTargetState(target);
|
setTargetState(target);
|
||||||
qsrand((uint)QDateTime::currentSecsSinceEpoch());
|
|
||||||
startTimer(1000);
|
startTimer(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool eventTest(QEvent *e) override
|
bool eventTest(QEvent *e) override
|
||||||
{
|
{
|
||||||
return QEventTransition::eventTest(e) && ((qrand() % 50) == 0);
|
return QEventTransition::eventTest(e) && QRandomGenerator::global()->bounded(50) == 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//! [4]
|
//! [4]
|
||||||
|
@ -57,8 +57,6 @@ int main(int argc, char *argv[])
|
|||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
Q_INIT_RESOURCE(subattaq);
|
Q_INIT_RESOURCE(subattaq);
|
||||||
|
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
#include <QtCore/QStateMachine>
|
#include <QtCore/QStateMachine>
|
||||||
#include <QtWidgets/QKeyEventTransition>
|
#include <QtWidgets/QKeyEventTransition>
|
||||||
#include <QtCore/QFinalState>
|
#include <QtCore/QFinalState>
|
||||||
|
#include <QtCore/QRandomGenerator>
|
||||||
|
|
||||||
PlayState::PlayState(GraphicsScene *scene, QState *parent)
|
PlayState::PlayState(GraphicsScene *scene, QState *parent)
|
||||||
: QState(parent),
|
: QState(parent),
|
||||||
@ -193,12 +194,12 @@ void LevelState::initializeLevel()
|
|||||||
for (int j = 0; j < subContent.second; ++j ) {
|
for (int j = 0; j < subContent.second; ++j ) {
|
||||||
SubMarine *sub = new SubMarine(submarineDesc.type, submarineDesc.name, submarineDesc.points);
|
SubMarine *sub = new SubMarine(submarineDesc.type, submarineDesc.name, submarineDesc.points);
|
||||||
scene->addItem(sub);
|
scene->addItem(sub);
|
||||||
int random = (qrand() % 15 + 1);
|
int random = QRandomGenerator::global()->bounded(15) + 1;
|
||||||
qreal x = random == 13 || random == 5 ? 0 : scene->width() - sub->size().width();
|
qreal x = random == 13 || random == 5 ? 0 : scene->width() - sub->size().width();
|
||||||
qreal y = scene->height() -(qrand() % 150 + 1) - sub->size().height();
|
qreal y = scene->height() -(QRandomGenerator::global()->bounded(150) + 1) - sub->size().height();
|
||||||
sub->setPos(x,y);
|
sub->setPos(x,y);
|
||||||
sub->setCurrentDirection(x == 0 ? SubMarine::Right : SubMarine::Left);
|
sub->setCurrentDirection(x == 0 ? SubMarine::Right : SubMarine::Left);
|
||||||
sub->setCurrentSpeed(qrand() % 3 + 1);
|
sub->setCurrentSpeed(QRandomGenerator::global()->bounded(3) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,7 @@
|
|||||||
|
|
||||||
//Qt
|
//Qt
|
||||||
#include <QtCore/QPropertyAnimation>
|
#include <QtCore/QPropertyAnimation>
|
||||||
|
#include <QtCore/QRandomGenerator>
|
||||||
#include <QtWidgets/QGraphicsScene>
|
#include <QtWidgets/QGraphicsScene>
|
||||||
|
|
||||||
//This state is describing when the boat is moving right
|
//This state is describing when the boat is moving right
|
||||||
@ -88,8 +89,8 @@ public:
|
|||||||
protected slots:
|
protected slots:
|
||||||
void onAnimationMovementValueChanged(const QVariant &)
|
void onAnimationMovementValueChanged(const QVariant &)
|
||||||
{
|
{
|
||||||
if (qrand() % 200 + 1 == 3)
|
if (QRandomGenerator::global()->bounded(200) + 1 == 3)
|
||||||
submarine->launchTorpedo(qrand() % 3 + 1);
|
submarine->launchTorpedo(QRandomGenerator::global()->bounded(3) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -80,8 +80,7 @@
|
|||||||
\snippet graphicsview/collidingmice/mouse.cpp 0
|
\snippet graphicsview/collidingmice/mouse.cpp 0
|
||||||
|
|
||||||
To calculate the various components of the mouse's color, we use
|
To calculate the various components of the mouse's color, we use
|
||||||
the global qrand() function which is a thread-safe version of the
|
\l QRandomGenerator.
|
||||||
standard C++ rand() function.
|
|
||||||
|
|
||||||
Then we call the \l {QGraphicsItem::setRotation()}{setRotation()} function
|
Then we call the \l {QGraphicsItem::setRotation()}{setRotation()} function
|
||||||
inherited from QGraphicsItem. Items live in their own local
|
inherited from QGraphicsItem. Items live in their own local
|
||||||
@ -178,12 +177,7 @@
|
|||||||
|
|
||||||
\snippet graphicsview/collidingmice/main.cpp 0
|
\snippet graphicsview/collidingmice/main.cpp 0
|
||||||
|
|
||||||
First, we create an application object and call the global
|
First, we create an application object and create the scene:
|
||||||
qsrand() function to specify the seed used to generate a new
|
|
||||||
random number sequence of pseudo random integers with the
|
|
||||||
previously mentioned qrand() function.
|
|
||||||
|
|
||||||
Then it is time to create the scene:
|
|
||||||
|
|
||||||
\snippet graphicsview/collidingmice/main.cpp 1
|
\snippet graphicsview/collidingmice/main.cpp 1
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@
|
|||||||
\snippet graphicsview/dragdroprobot/coloritem.cpp 0
|
\snippet graphicsview/dragdroprobot/coloritem.cpp 0
|
||||||
|
|
||||||
\c ColorItem's constructor assigns an opaque random color to its color
|
\c ColorItem's constructor assigns an opaque random color to its color
|
||||||
member by making use of qrand(). For improved usability, it assigns a
|
member by making use of \l QRandomGenerator. For improved usability, it assigns a
|
||||||
tooltip that provides a useful hint to the user, and it also sets a
|
tooltip that provides a useful hint to the user, and it also sets a
|
||||||
suitable cursor. This ensures that the cursor will chance to
|
suitable cursor. This ensures that the cursor will chance to
|
||||||
Qt::OpenHandCursor when the mouse pointer hovers over the item.
|
Qt::OpenHandCursor when the mouse pointer hovers over the item.
|
||||||
|
@ -424,9 +424,8 @@
|
|||||||
\section1 The main() Function
|
\section1 The main() Function
|
||||||
|
|
||||||
In contrast to the complexity of the rest of this example, the \c main()
|
In contrast to the complexity of the rest of this example, the \c main()
|
||||||
function is very simple: We create a QApplication instance, seed the
|
function is very simple: We create a QApplication instance, then create and
|
||||||
randomizer using qsrand(), and then create and show an instance of \c
|
show an instance of \c GraphWidget. Because all nodes in the grid are moved
|
||||||
GraphWidget. Because all nodes in the grid are moved initially, the \c
|
initially, the \c GraphWidget timer will start immediately after control
|
||||||
GraphWidget timer will start immediately after control has returned to the
|
has returned to the event loop.
|
||||||
event loop.
|
|
||||||
*/
|
*/
|
||||||
|
@ -122,10 +122,8 @@ void MainWindow::setupPuzzle()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qsrand(QCursor::pos().x() ^ QCursor::pos().y());
|
|
||||||
|
|
||||||
for (int i = 0; i < piecesList->count(); ++i) {
|
for (int i = 0; i < piecesList->count(); ++i) {
|
||||||
if (int(2.0*qrand()/(RAND_MAX+1.0)) == 1) {
|
if (QRandomGenerator::global()->bounded(2) == 1) {
|
||||||
QListWidgetItem *item = piecesList->takeItem(i);
|
QListWidgetItem *item = piecesList->takeItem(i);
|
||||||
piecesList->insertItem(0, item);
|
piecesList->insertItem(0, item);
|
||||||
}
|
}
|
||||||
|
@ -414,7 +414,7 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
|
|||||||
|
|
||||||
CircleItem::CircleItem(int size, int x, int y) : ItemBase(size, x, y)
|
CircleItem::CircleItem(int size, int x, int y) : ItemBase(size, x, y)
|
||||||
{
|
{
|
||||||
m_color = QColor::fromHsv(rand() % 360, 255, 255);
|
m_color = QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
|
#include <QtCore/QRandomGenerator>
|
||||||
#include <QtGui/qmatrix4x4.h>
|
#include <QtGui/qmatrix4x4.h>
|
||||||
#include <QtGui/qvector3d.h>
|
#include <QtGui/qvector3d.h>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
@ -1072,13 +1073,16 @@ void Scene::newItem(ItemDialog::ItemType type)
|
|||||||
QSize size = sceneRect().size().toSize();
|
QSize size = sceneRect().size().toSize();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ItemDialog::QtBoxItem:
|
case ItemDialog::QtBoxItem:
|
||||||
addItem(new QtBox(64, rand() % (size.width() - 64) + 32, rand() % (size.height() - 64) + 32));
|
addItem(new QtBox(64, QRandomGenerator::global()->bounded(size.width() - 64) + 32,
|
||||||
|
QRandomGenerator::global()->bounded(size.height() - 64) + 32));
|
||||||
break;
|
break;
|
||||||
case ItemDialog::CircleItem:
|
case ItemDialog::CircleItem:
|
||||||
addItem(new CircleItem(64, rand() % (size.width() - 64) + 32, rand() % (size.height() - 64) + 32));
|
addItem(new CircleItem(64, QRandomGenerator::global()->bounded(size.width() - 64) + 32,
|
||||||
|
QRandomGenerator::global()->bounded(size.height() - 64) + 32));
|
||||||
break;
|
break;
|
||||||
case ItemDialog::SquareItem:
|
case ItemDialog::SquareItem:
|
||||||
addItem(new SquareItem(64, rand() % (size.width() - 64) + 32, rand() % (size.height() - 64) + 32));
|
addItem(new SquareItem(64, QRandomGenerator::global()->bounded(size.width() - 64) + 32,
|
||||||
|
QRandomGenerator::global()->bounded(size.height() - 64) + 32));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -60,7 +60,6 @@ static const int MouseCount = 7;
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
|
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
|
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
@ -70,9 +71,9 @@ static qreal normalizeAngle(qreal angle)
|
|||||||
//! [0]
|
//! [0]
|
||||||
Mouse::Mouse()
|
Mouse::Mouse()
|
||||||
: angle(0), speed(0), mouseEyeDirection(0),
|
: angle(0), speed(0), mouseEyeDirection(0),
|
||||||
color(qrand() % 256, qrand() % 256, qrand() % 256)
|
color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
|
||||||
{
|
{
|
||||||
setRotation(qrand() % (360 * 16));
|
setRotation(QRandomGenerator::global()->bounded(360 * 16));
|
||||||
}
|
}
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
@ -185,16 +186,16 @@ void Mouse::advance(int step)
|
|||||||
|
|
||||||
// Add some random movement
|
// Add some random movement
|
||||||
//! [10]
|
//! [10]
|
||||||
if (dangerMice.size() > 1 && (qrand() % 10) == 0) {
|
if (dangerMice.size() > 1 && QRandomGenerator::global()->bounded(10) == 0) {
|
||||||
if (qrand() % 1)
|
if (QRandomGenerator::global()->bounded(1))
|
||||||
angle += (qrand() % 100) / 500.0;
|
angle += QRandomGenerator::global()->bounded(1 / 500.0);
|
||||||
else
|
else
|
||||||
angle -= (qrand() % 100) / 500.0;
|
angle -= QRandomGenerator::global()->bounded(1 / 500.0);
|
||||||
}
|
}
|
||||||
//! [10]
|
//! [10]
|
||||||
|
|
||||||
//! [11]
|
//! [11]
|
||||||
speed += (-50 + qrand() % 100) / 100.0;
|
speed += (-50 + QRandomGenerator::global()->bounded(100)) / 100.0;
|
||||||
|
|
||||||
qreal dx = ::sin(angle) * 10;
|
qreal dx = ::sin(angle) * 10;
|
||||||
mouseEyeDirection = (qAbs(dx / 5) < 1) ? 0 : dx / 5;
|
mouseEyeDirection = (qAbs(dx / 5) < 1) ? 0 : dx / 5;
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
ColorItem::ColorItem()
|
ColorItem::ColorItem()
|
||||||
: color(qrand() % 256, qrand() % 256, qrand() % 256)
|
: color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
|
||||||
{
|
{
|
||||||
setToolTip(QString("QColor(%1, %2, %3)\n%4")
|
setToolTip(QString("QColor(%1, %2, %3)\n%4")
|
||||||
.arg(color.red()).arg(color.green()).arg(color.blue())
|
.arg(color.red()).arg(color.green()).arg(color.blue())
|
||||||
@ -107,7 +107,7 @@ void ColorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
|
|
||||||
//! [6]
|
//! [6]
|
||||||
static int n = 0;
|
static int n = 0;
|
||||||
if (n++ > 2 && (qrand() % 3) == 0) {
|
if (n++ > 2 && QRandomGenerator::global()->bounded(3) == 0) {
|
||||||
QImage image(":/images/head.png");
|
QImage image(":/images/head.png");
|
||||||
mime->setImageData(image);
|
mime->setImageData(image);
|
||||||
|
|
||||||
|
@ -73,7 +73,6 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
|
||||||
//! [0]
|
//! [0]
|
||||||
//! [1]
|
//! [1]
|
||||||
QGraphicsScene scene(-200, -200, 400, 400);
|
QGraphicsScene scene(-200, -200, 400, 400);
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
GraphWidget::GraphWidget(QWidget *parent)
|
GraphWidget::GraphWidget(QWidget *parent)
|
||||||
@ -247,7 +248,7 @@ void GraphWidget::shuffle()
|
|||||||
{
|
{
|
||||||
foreach (QGraphicsItem *item, scene()->items()) {
|
foreach (QGraphicsItem *item, scene()->items()) {
|
||||||
if (qgraphicsitem_cast<Node *>(item))
|
if (qgraphicsitem_cast<Node *>(item))
|
||||||
item->setPos(-150 + qrand() % 300, -150 + qrand() % 300);
|
item->setPos(-150 + QRandomGenerator::global()->bounded(300), -150 + QRandomGenerator::global()->bounded(300));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,6 @@
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
|
||||||
|
|
||||||
GraphWidget *widget = new GraphWidget;
|
GraphWidget *widget = new GraphWidget;
|
||||||
|
|
||||||
|
@ -114,8 +114,6 @@ void MainWindow::setupPuzzle()
|
|||||||
(puzzleImage.height() - size) / 2, size, size).scaled(puzzleWidget->imageSize(),
|
(puzzleImage.height() - size) / 2, size, size).scaled(puzzleWidget->imageSize(),
|
||||||
puzzleWidget->imageSize(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
puzzleWidget->imageSize(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||||
|
|
||||||
qsrand(QCursor::pos().x() ^ QCursor::pos().y());
|
|
||||||
|
|
||||||
model->addPieces(puzzleImage);
|
model->addPieces(puzzleImage);
|
||||||
puzzleWidget->clear();
|
puzzleWidget->clear();
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
PiecesModel::PiecesModel(int pieceSize, QObject *parent)
|
PiecesModel::PiecesModel(int pieceSize, QObject *parent)
|
||||||
: QAbstractListModel(parent), m_PieceSize(pieceSize)
|
: QAbstractListModel(parent), m_PieceSize(pieceSize)
|
||||||
@ -77,7 +78,7 @@ QVariant PiecesModel::data(const QModelIndex &index, int role) const
|
|||||||
void PiecesModel::addPiece(const QPixmap &pixmap, const QPoint &location)
|
void PiecesModel::addPiece(const QPixmap &pixmap, const QPoint &location)
|
||||||
{
|
{
|
||||||
int row;
|
int row;
|
||||||
if (int(2.0 * qrand() / (RAND_MAX + 1.0)) == 1)
|
if (QRandomGenerator::global()->bounded(2) == 1)
|
||||||
row = 0;
|
row = 0;
|
||||||
else
|
else
|
||||||
row = pixmaps.size();
|
row = pixmaps.size();
|
||||||
|
@ -50,6 +50,8 @@
|
|||||||
|
|
||||||
#include "toolbar.h"
|
#include "toolbar.h"
|
||||||
|
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
@ -257,7 +259,7 @@ void ToolBar::randomize()
|
|||||||
QList<QAction *> randomized;
|
QList<QAction *> randomized;
|
||||||
QList<QAction *> actions = this->actions();
|
QList<QAction *> actions = this->actions();
|
||||||
while (!actions.isEmpty()) {
|
while (!actions.isEmpty()) {
|
||||||
QAction *action = actions.takeAt(rand() % actions.size());
|
QAction *action = actions.takeAt(QRandomGenerator::global()->bounded(actions.size()));
|
||||||
randomized.append(action);
|
randomized.append(action);
|
||||||
}
|
}
|
||||||
clear();
|
clear();
|
||||||
|
@ -248,11 +248,9 @@ void Window::movePlayer(Direction direction)
|
|||||||
|
|
||||||
void Window::setupMap()
|
void Window::setupMap()
|
||||||
{
|
{
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
|
||||||
|
|
||||||
for (int x = 0; x < WIDTH; ++x)
|
for (int x = 0; x < WIDTH; ++x)
|
||||||
for (int y = 0; y < HEIGHT; ++y) {
|
for (int y = 0; y < HEIGHT; ++y) {
|
||||||
if (x == 0 || x == WIDTH - 1 || y == 0 || y == HEIGHT - 1 || qrand() % 40 == 0)
|
if (x == 0 || x == WIDTH - 1 || y == 0 || y == HEIGHT - 1 || QRandomGenerator::global()->bounded(40) == 0)
|
||||||
map[x][y] = '#';
|
map[x][y] = '#';
|
||||||
else
|
else
|
||||||
map[x][y] = '.';
|
map[x][y] = '.';
|
||||||
|
@ -101,7 +101,7 @@ QRect BasicToolsPlugin::mouseMove(const QString &brush, QPainter &painter,
|
|||||||
thickness, thickness);
|
thickness, thickness);
|
||||||
}
|
}
|
||||||
} else if (brush == tr("Random Letters")) {
|
} else if (brush == tr("Random Letters")) {
|
||||||
QChar ch('A' + (qrand() % 26));
|
QChar ch(QRandomGenerator::global()->bounded('A', 'Z' + 1));
|
||||||
|
|
||||||
QFont biggerFont = painter.font();
|
QFont biggerFont = painter.font();
|
||||||
biggerFont.setBold(true);
|
biggerFont.setBold(true);
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
#include <QUndoStack>
|
#include <QUndoStack>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
@ -321,7 +322,7 @@ void MainWindow::newDocument()
|
|||||||
|
|
||||||
static QColor randomColor()
|
static QColor randomColor()
|
||||||
{
|
{
|
||||||
int r = (int) (3.0*(rand()/(RAND_MAX + 1.0)));
|
int r = QRandomGenerator::global()->bounded(3);
|
||||||
switch (r) {
|
switch (r) {
|
||||||
case 0:
|
case 0:
|
||||||
return Qt::red;
|
return Qt::red;
|
||||||
@ -337,10 +338,10 @@ static QRect randomRect(const QSize &s)
|
|||||||
{
|
{
|
||||||
QSize min = Shape::minSize;
|
QSize min = Shape::minSize;
|
||||||
|
|
||||||
int left = (int) ((0.0 + s.width() - min.width())*(rand()/(RAND_MAX + 1.0)));
|
int left = (int) ((0.0 + s.width() - min.width())*(QRandomGenerator::global()->bounded(1.0)));
|
||||||
int top = (int) ((0.0 + s.height() - min.height())*(rand()/(RAND_MAX + 1.0)));
|
int top = (int) ((0.0 + s.height() - min.height())*(QRandomGenerator::global()->bounded(1.0)));
|
||||||
int width = (int) ((0.0 + s.width() - left - min.width())*(rand()/(RAND_MAX + 1.0))) + min.width();
|
int width = (int) ((0.0 + s.width() - left - min.width())*(QRandomGenerator::global()->bounded(1.0))) + min.width();
|
||||||
int height = (int) ((0.0 + s.height() - top - min.height())*(rand()/(RAND_MAX + 1.0))) + min.height();
|
int height = (int) ((0.0 + s.height() - top - min.height())*(QRandomGenerator::global()->bounded(1.0))) + min.height();
|
||||||
|
|
||||||
return QRect(left, top, width, height);
|
return QRect(left, top, width, height);
|
||||||
}
|
}
|
||||||
|
@ -65,8 +65,7 @@ DiagramItem::DiagramItem(DiagramType diagramType, QGraphicsItem *item)
|
|||||||
setPolygon(trianglePolygon);
|
setPolygon(trianglePolygon);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor color(static_cast<int>(qrand()) % 256,
|
QColor color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256));
|
||||||
static_cast<int>(qrand()) % 256, static_cast<int>(qrand()) % 256);
|
|
||||||
QBrush brush(color);
|
QBrush brush(color);
|
||||||
setBrush(brush);
|
setBrush(brush);
|
||||||
setFlag(QGraphicsItem::ItemIsSelectable);
|
setFlag(QGraphicsItem::ItemIsSelectable);
|
||||||
|
@ -59,6 +59,5 @@ int main(int argc, char *argv[])
|
|||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
TetrixWindow window;
|
TetrixWindow window;
|
||||||
window.show();
|
window.show();
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
//! [0]
|
//! [0]
|
||||||
void TetrixPiece::setRandomShape()
|
void TetrixPiece::setRandomShape()
|
||||||
{
|
{
|
||||||
setShape(TetrixShape(qrand() % 7 + 1));
|
setShape(TetrixShape(QRandomGenerator::global()->bounded(7) + 1));
|
||||||
}
|
}
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
@ -57,7 +57,6 @@ int main(int argc, char *argv[])
|
|||||||
Q_INIT_RESOURCE(tooltips);
|
Q_INIT_RESOURCE(tooltips);
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
|
|
||||||
SortingBox sortingBox;
|
SortingBox sortingBox;
|
||||||
sortingBox.show();
|
sortingBox.show();
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
@ -292,7 +292,7 @@ QPoint SortingBox::initialItemPosition(const QPainterPath &path)
|
|||||||
//! [24]
|
//! [24]
|
||||||
QPoint SortingBox::randomItemPosition()
|
QPoint SortingBox::randomItemPosition()
|
||||||
{
|
{
|
||||||
return QPoint(qrand() % (width() - 120), qrand() % (height() - 120));
|
return QPoint(QRandomGenerator::global()->bounded(width() - 120), QRandomGenerator::global()->bounded(height() - 120));
|
||||||
}
|
}
|
||||||
//! [24]
|
//! [24]
|
||||||
|
|
||||||
@ -306,6 +306,6 @@ QColor SortingBox::initialItemColor()
|
|||||||
//! [26]
|
//! [26]
|
||||||
QColor SortingBox::randomItemColor()
|
QColor SortingBox::randomItemColor()
|
||||||
{
|
{
|
||||||
return QColor::fromHsv(qrand() % 256, 255, 190);
|
return QColor::fromHsv(QRandomGenerator::global()->bounded(256), 255, 190);
|
||||||
}
|
}
|
||||||
//! [26]
|
//! [26]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2016 The Qt Company Ltd.
|
||||||
** Copyright (C) 2016 Intel Corporation.
|
** Copyright (C) 2017 Intel Corporation.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the QtCore module of the Qt Toolkit.
|
** This file is part of the QtCore module of the Qt Toolkit.
|
||||||
@ -48,6 +48,7 @@
|
|||||||
#include <qdir.h>
|
#include <qdir.h>
|
||||||
#include <qelapsedtimer.h>
|
#include <qelapsedtimer.h>
|
||||||
#include <qfileinfo.h>
|
#include <qfileinfo.h>
|
||||||
|
#include <qrandom.h>
|
||||||
#include <qregexp.h>
|
#include <qregexp.h>
|
||||||
#include <qwineventnotifier.h>
|
#include <qwineventnotifier.h>
|
||||||
#include <private/qsystemlibrary_p.h>
|
#include <private/qsystemlibrary_p.h>
|
||||||
@ -99,10 +100,8 @@ static void qt_create_pipe(Q_PIPE *pipe, bool isInputPipe)
|
|||||||
wchar_t pipeName[256];
|
wchar_t pipeName[256];
|
||||||
unsigned int attempts = 1000;
|
unsigned int attempts = 1000;
|
||||||
forever {
|
forever {
|
||||||
// ### The user must make sure to call qsrand() to make the pipe names less predictable.
|
|
||||||
// ### Replace the call to qrand() with a secure version, once we have it in Qt.
|
|
||||||
_snwprintf(pipeName, sizeof(pipeName) / sizeof(pipeName[0]),
|
_snwprintf(pipeName, sizeof(pipeName) / sizeof(pipeName[0]),
|
||||||
L"\\\\.\\pipe\\qt-%X", qrand());
|
L"\\\\.\\pipe\\qt-%X", QRandomGenerator::global()->generate());
|
||||||
|
|
||||||
DWORD dwOpenMode = FILE_FLAG_OVERLAPPED;
|
DWORD dwOpenMode = FILE_FLAG_OVERLAPPED;
|
||||||
DWORD dwOutputBufferSize = 0;
|
DWORD dwOutputBufferSize = 0;
|
||||||
|
@ -165,7 +165,7 @@ QFileSystemEntry::NativePath QTemporaryFileName::generateNext()
|
|||||||
|
|
||||||
Char *rIter = placeholderEnd;
|
Char *rIter = placeholderEnd;
|
||||||
while (rIter != placeholderStart) {
|
while (rIter != placeholderStart) {
|
||||||
quint32 rnd = QRandomGenerator::generate();
|
quint32 rnd = QRandomGenerator::global()->generate();
|
||||||
auto applyOne = [&]() {
|
auto applyOne = [&]() {
|
||||||
quint32 v = rnd & ((1 << BitsPerCharacter) - 1);
|
quint32 v = rnd & ((1 << BitsPerCharacter) - 1);
|
||||||
rnd >>= BitsPerCharacter;
|
rnd >>= BitsPerCharacter;
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
|
|
||||||
#include <qpainter.h>
|
#include <qpainter.h>
|
||||||
#include <qimage.h>
|
#include <qimage.h>
|
||||||
|
#include <qrandom.h>
|
||||||
#include <qscreen.h>
|
#include <qscreen.h>
|
||||||
|
|
||||||
#include <private/qguiapplication_p.h>
|
#include <private/qguiapplication_p.h>
|
||||||
@ -252,7 +253,7 @@ QImage *QBlittablePlatformPixmap::overlay()
|
|||||||
m_rasterOverlay->size() != QSize(w,h)){
|
m_rasterOverlay->size() != QSize(w,h)){
|
||||||
m_rasterOverlay = new QImage(w,h,QImage::Format_ARGB32_Premultiplied);
|
m_rasterOverlay = new QImage(w,h,QImage::Format_ARGB32_Premultiplied);
|
||||||
m_rasterOverlay->fill(0x00000000);
|
m_rasterOverlay->fill(0x00000000);
|
||||||
uint color = (qrand() % 11)+7;
|
uint color = QRandomGenerator::global()->bounded(11)+7;
|
||||||
m_overlayColor = QColor(Qt::GlobalColor(color));
|
m_overlayColor = QColor(Qt::GlobalColor(color));
|
||||||
m_overlayColor.setAlpha(0x88);
|
m_overlayColor.setAlpha(0x88);
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include <private/qopenglcontext_p.h>
|
#include <private/qopenglcontext_p.h>
|
||||||
#include <private/qrgba64_p.h>
|
#include <private/qrgba64_p.h>
|
||||||
#include <QtCore/qmutex.h>
|
#include <QtCore/qmutex.h>
|
||||||
|
#include <QtCore/qrandom.h>
|
||||||
#include "qopenglfunctions.h"
|
#include "qopenglfunctions.h"
|
||||||
#include "qopenglextensions_p.h"
|
#include "qopenglextensions_p.h"
|
||||||
|
|
||||||
@ -137,7 +138,7 @@ GLuint QOpenGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient
|
|||||||
{
|
{
|
||||||
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
|
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
|
||||||
if (cache.size() == maxCacheSize()) {
|
if (cache.size() == maxCacheSize()) {
|
||||||
int elem_to_remove = qrand() % maxCacheSize();
|
int elem_to_remove = QRandomGenerator::global()->bounded(maxCacheSize());
|
||||||
quint64 key = cache.keys()[elem_to_remove];
|
quint64 key = cache.keys()[elem_to_remove];
|
||||||
|
|
||||||
// need to call glDeleteTextures on each removed cache entry:
|
// need to call glDeleteTextures on each removed cache entry:
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <qbitmap.h>
|
#include <qbitmap.h>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
#include <qrandom.h>
|
||||||
|
|
||||||
// #include <private/qdatabuffer_p.h>
|
// #include <private/qdatabuffer_p.h>
|
||||||
// #include <private/qpainter_p.h>
|
// #include <private/qpainter_p.h>
|
||||||
@ -4229,7 +4230,7 @@ protected:
|
|||||||
QSharedPointer<const CacheInfo> addCacheElement(quint64 hash_val, const QGradient &gradient, int opacity) {
|
QSharedPointer<const CacheInfo> addCacheElement(quint64 hash_val, const QGradient &gradient, int opacity) {
|
||||||
if (cache.size() == maxCacheSize()) {
|
if (cache.size() == maxCacheSize()) {
|
||||||
// may remove more than 1, but OK
|
// may remove more than 1, but OK
|
||||||
cache.erase(cache.begin() + (qrand() % maxCacheSize()));
|
cache.erase(cache.begin() + QRandomGenerator::global()->bounded(maxCacheSize()));
|
||||||
}
|
}
|
||||||
auto cache_entry = QSharedPointer<CacheInfo>::create(gradient.stops(), opacity, gradient.interpolationMode());
|
auto cache_entry = QSharedPointer<CacheInfo>::create(gradient.stops(), opacity, gradient.interpolationMode());
|
||||||
generateGradientColorTable(gradient, cache_entry->buffer64, paletteSize(), opacity);
|
generateGradientColorTable(gradient, cache_entry->buffer64, paletteSize(), opacity);
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
#include <qcoreapplication.h>
|
#include <qcoreapplication.h>
|
||||||
#include <qdatetime.h>
|
#include <qdatetime.h>
|
||||||
#include <qthreadstorage.h>
|
#include <qrandom.h>
|
||||||
#include <qurl.h>
|
#include <qurl.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -50,7 +50,6 @@
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QDnsLookupThreadPool, theDnsLookupThreadPool);
|
Q_GLOBAL_STATIC(QDnsLookupThreadPool, theDnsLookupThreadPool);
|
||||||
Q_GLOBAL_STATIC(QThreadStorage<bool *>, theDnsLookupSeedStorage);
|
|
||||||
|
|
||||||
static bool qt_qdnsmailexchangerecord_less_than(const QDnsMailExchangeRecord &r1, const QDnsMailExchangeRecord &r2)
|
static bool qt_qdnsmailexchangerecord_less_than(const QDnsMailExchangeRecord &r1, const QDnsMailExchangeRecord &r2)
|
||||||
{
|
{
|
||||||
@ -85,7 +84,7 @@ static void qt_qdnsmailexchangerecord_sort(QList<QDnsMailExchangeRecord> &record
|
|||||||
|
|
||||||
// Randomize the slice of records.
|
// Randomize the slice of records.
|
||||||
while (!slice.isEmpty()) {
|
while (!slice.isEmpty()) {
|
||||||
const unsigned int pos = qrand() % slice.size();
|
const unsigned int pos = QRandomGenerator::global()->bounded(slice.size());
|
||||||
records[i++] = slice.takeAt(pos);
|
records[i++] = slice.takeAt(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,7 +133,7 @@ static void qt_qdnsservicerecord_sort(QList<QDnsServiceRecord> &records)
|
|||||||
|
|
||||||
// Order the slice of records.
|
// Order the slice of records.
|
||||||
while (!slice.isEmpty()) {
|
while (!slice.isEmpty()) {
|
||||||
const unsigned int weightThreshold = qrand() % (sliceWeight + 1);
|
const unsigned int weightThreshold = QRandomGenerator::global()->bounded(sliceWeight + 1);
|
||||||
unsigned int summedWeight = 0;
|
unsigned int summedWeight = 0;
|
||||||
for (int j = 0; j < slice.size(); ++j) {
|
for (int j = 0; j < slice.size(); ++j) {
|
||||||
summedWeight += slice.at(j).weight();
|
summedWeight += slice.at(j).weight();
|
||||||
@ -1011,10 +1010,6 @@ void QDnsLookupRunnable::run()
|
|||||||
query(requestType, requestName, nameserver, &reply);
|
query(requestType, requestName, nameserver, &reply);
|
||||||
|
|
||||||
// Sort results.
|
// Sort results.
|
||||||
if (!theDnsLookupSeedStorage()->hasLocalData()) {
|
|
||||||
qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) ^ reinterpret_cast<quintptr>(this));
|
|
||||||
theDnsLookupSeedStorage()->setLocalData(new bool(true));
|
|
||||||
}
|
|
||||||
qt_qdnsmailexchangerecord_sort(reply.mailExchangeRecords);
|
qt_qdnsmailexchangerecord_sort(reply.mailExchangeRecords);
|
||||||
qt_qdnsservicerecord_sort(reply.serviceRecords);
|
qt_qdnsservicerecord_sort(reply.serviceRecords);
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include <private/qdrawhelper_p.h>
|
#include <private/qdrawhelper_p.h>
|
||||||
#include <private/qgl_p.h>
|
#include <private/qgl_p.h>
|
||||||
#include <QtCore/qmutex.h>
|
#include <QtCore/qmutex.h>
|
||||||
|
#include <QtCore/qrandom.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -130,7 +131,7 @@ GLuint QGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient &gra
|
|||||||
{
|
{
|
||||||
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
|
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
|
||||||
if (cache.size() == maxCacheSize()) {
|
if (cache.size() == maxCacheSize()) {
|
||||||
int elem_to_remove = qrand() % maxCacheSize();
|
int elem_to_remove = QRandomGenerator::global()->bounded(maxCacheSize());
|
||||||
quint64 key = cache.keys()[elem_to_remove];
|
quint64 key = cache.keys()[elem_to_remove];
|
||||||
|
|
||||||
// need to call glDeleteTextures on each removed cache entry:
|
// need to call glDeleteTextures on each removed cache entry:
|
||||||
|
@ -2204,13 +2204,13 @@ InstanceCounter slowMap(const InstanceCounter &in)
|
|||||||
|
|
||||||
InstanceCounter fastMap(const InstanceCounter &in)
|
InstanceCounter fastMap(const InstanceCounter &in)
|
||||||
{
|
{
|
||||||
QTest::qSleep(rand() % 2 + 1);
|
QTest::qSleep(QRandomGenerator::global()->bounded(2) + 1);
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
void slowReduce(int &result, const InstanceCounter&)
|
void slowReduce(int &result, const InstanceCounter&)
|
||||||
{
|
{
|
||||||
QTest::qSleep(rand() % 4 + 1);
|
QTest::qSleep(QRandomGenerator::global()->bounded(4) + 1);
|
||||||
++result;
|
++result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <QtAlgorithms>
|
#include <QtAlgorithms>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <qplatformdefs.h>
|
#include <qplatformdefs.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@ -174,8 +175,7 @@ static inline QByteArray generateDataBlock(int blockSize, QString text, qint64 u
|
|||||||
|
|
||||||
static qint64 counter = 0;
|
static qint64 counter = 0;
|
||||||
|
|
||||||
qint64 randomBits = ((qint64)qrand() << 32)
|
qint64 randomBits = QRandomGenerator::global()->generate64();
|
||||||
| ((qint64)qrand() & 0x00000000ffffffff);
|
|
||||||
|
|
||||||
appendRaw(block, randomBits);
|
appendRaw(block, randomBits);
|
||||||
appendRaw(block, userBits);
|
appendRaw(block, userBits);
|
||||||
|
@ -2362,8 +2362,8 @@ void tst_QObject::testUserData()
|
|||||||
|
|
||||||
// Randomize the table a bit
|
// Randomize the table a bit
|
||||||
for (int i=0; i<100; ++i) {
|
for (int i=0; i<100; ++i) {
|
||||||
int p1 = rand() % USER_DATA_COUNT;
|
int p1 = QRandomGenerator::global()->bounded(USER_DATA_COUNT);
|
||||||
int p2 = rand() % USER_DATA_COUNT;
|
int p2 = QRandomGenerator::global()->bounded(USER_DATA_COUNT);
|
||||||
|
|
||||||
int tmp = user_data_ids[p1];
|
int tmp = user_data_ids[p1];
|
||||||
user_data_ids[p1] = user_data_ids[p2];
|
user_data_ids[p1] = user_data_ids[p2];
|
||||||
|
@ -115,7 +115,6 @@ Q_CONSTRUCTOR_FUNCTION(initializeLang)
|
|||||||
|
|
||||||
static QString seedAndTemplate()
|
static QString seedAndTemplate()
|
||||||
{
|
{
|
||||||
qsrand(QDateTime::currentSecsSinceEpoch());
|
|
||||||
return QDir::tempPath() + "/tst_qmimedatabase-XXXXXX";
|
return QDir::tempPath() + "/tst_qmimedatabase-XXXXXX";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,9 +35,6 @@ int main(int argc, char **argv)
|
|||||||
Q_UNUSED(argc)
|
Q_UNUSED(argc)
|
||||||
Q_UNUSED(argv)
|
Q_UNUSED(argv)
|
||||||
|
|
||||||
// First, break QUuid.
|
|
||||||
qrand();
|
|
||||||
|
|
||||||
// Now print a few uuids.
|
// Now print a few uuids.
|
||||||
printf("%s", qPrintable(QUuid::createUuid().toString()));
|
printf("%s", qPrintable(QUuid::createUuid().toString()));
|
||||||
printf("%s", qPrintable(QUuid::createUuid().toString()));
|
printf("%s", qPrintable(QUuid::createUuid().toString()));
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <qresultstore.h>
|
#include <qresultstore.h>
|
||||||
#include <qthreadpool.h>
|
#include <qthreadpool.h>
|
||||||
#include <qexception.h>
|
#include <qexception.h>
|
||||||
|
#include <qrandom.h>
|
||||||
#include <private/qfutureinterface_p.h>
|
#include <private/qfutureinterface_p.h>
|
||||||
|
|
||||||
// COM interface macro.
|
// COM interface macro.
|
||||||
@ -1456,7 +1457,7 @@ void tst_QFuture::nonGlobalThreadPool()
|
|||||||
|
|
||||||
void run() Q_DECL_OVERRIDE
|
void run() Q_DECL_OVERRIDE
|
||||||
{
|
{
|
||||||
const int ms = 100 + (qrand() % 100 - 100/2);
|
const int ms = 100 + (QRandomGenerator::global()->bounded(100) - 100/2);
|
||||||
QThread::msleep(ms);
|
QThread::msleep(ms);
|
||||||
reportResult(Answer);
|
reportResult(Answer);
|
||||||
reportFinished();
|
reportFinished();
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include <qalgorithms.h>
|
#include <qalgorithms.h>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
#define Q_TEST_PERFORMANCE 0
|
#define Q_TEST_PERFORMANCE 0
|
||||||
@ -133,7 +134,7 @@ QVector<DataType> generateData(QString dataSetType, const int length)
|
|||||||
QVector<DataType> container;
|
QVector<DataType> container;
|
||||||
if (dataSetType == "Random") {
|
if (dataSetType == "Random") {
|
||||||
for (int i = 0; i < length; ++i)
|
for (int i = 0; i < length; ++i)
|
||||||
container.append(rand());
|
container.append(QRandomGenerator::global()->generate());
|
||||||
} else if (dataSetType == "Ascending") {
|
} else if (dataSetType == "Ascending") {
|
||||||
for (int i = 0; i < length; ++i)
|
for (int i = 0; i < length; ++i)
|
||||||
container.append(i);
|
container.append(i);
|
||||||
@ -1082,12 +1083,12 @@ void tst_QAlgorithms::popCount_data_impl(size_t sizeof_T_Int)
|
|||||||
// and some random ones:
|
// and some random ones:
|
||||||
if (sizeof_T_Int >= 8)
|
if (sizeof_T_Int >= 8)
|
||||||
for (size_t i = 0; i < 1000; ++i) {
|
for (size_t i = 0; i < 1000; ++i) {
|
||||||
const quint64 input = quint64(qrand()) << 32 | quint32(qrand());
|
const quint64 input = QRandomGenerator::global()->generate64();
|
||||||
QTest::addRow("0x%016llx", input) << input << bitsSetInInt64(input);
|
QTest::addRow("0x%016llx", input) << input << bitsSetInInt64(input);
|
||||||
}
|
}
|
||||||
else if (sizeof_T_Int >= 2)
|
else if (sizeof_T_Int >= 2)
|
||||||
for (size_t i = 0; i < 1000 ; ++i) {
|
for (size_t i = 0; i < 1000 ; ++i) {
|
||||||
const quint32 input = qrand();
|
const quint32 input = QRandomGenerator::global()->generate();
|
||||||
if (sizeof_T_Int >= 4)
|
if (sizeof_T_Int >= 4)
|
||||||
QTest::addRow("0x%08x", input) << quint64(input) << bitsSetInInt(input);
|
QTest::addRow("0x%08x", input) << quint64(input) << bitsSetInInt(input);
|
||||||
else
|
else
|
||||||
@ -1129,7 +1130,7 @@ void tst_QAlgorithms::countTrailing_data_impl(size_t sizeof_T_Int)
|
|||||||
// and some random ones:
|
// and some random ones:
|
||||||
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
|
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
|
||||||
for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary
|
for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary
|
||||||
const quint64 r = quint64(qrand()) << 32 | quint32(qrand());
|
const quint64 r = QRandomGenerator::global()->generate64();
|
||||||
const quint64 b = Q_UINT64_C(1) << i;
|
const quint64 b = Q_UINT64_C(1) << i;
|
||||||
const quint64 mask = ((~(b-1)) ^ b) & type_mask;
|
const quint64 mask = ((~(b-1)) ^ b) & type_mask;
|
||||||
const quint64 input = (r&mask) | b;
|
const quint64 input = (r&mask) | b;
|
||||||
@ -1166,7 +1167,7 @@ void tst_QAlgorithms::countLeading_data_impl(size_t sizeof_T_Int)
|
|||||||
// and some random ones:
|
// and some random ones:
|
||||||
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
|
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
|
||||||
for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary
|
for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary
|
||||||
const quint64 r = quint64(qrand()) << 32 | quint32(qrand());
|
const quint64 r = QRandomGenerator::global()->generate64();
|
||||||
const quint64 b = Q_UINT64_C(1) << i;
|
const quint64 b = Q_UINT64_C(1) << i;
|
||||||
const quint64 mask = b-1;
|
const quint64 mask = b-1;
|
||||||
const quint64 input = (r&mask) | b;
|
const quint64 input = (r&mask) | b;
|
||||||
|
@ -1884,7 +1884,7 @@ class StrongThread: public QThread
|
|||||||
protected:
|
protected:
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
usleep(rand() % 2000);
|
usleep(QRandomGenerator::global()->bounded(2000));
|
||||||
ptr->ref();
|
ptr->ref();
|
||||||
ptr.clear();
|
ptr.clear();
|
||||||
}
|
}
|
||||||
@ -1897,7 +1897,7 @@ class WeakThread: public QThread
|
|||||||
protected:
|
protected:
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
usleep(rand() % 2000);
|
usleep(QRandomGenerator::global()->bounded(2000));
|
||||||
QSharedPointer<ThreadData> ptr = weak;
|
QSharedPointer<ThreadData> ptr = weak;
|
||||||
if (ptr)
|
if (ptr)
|
||||||
ptr->ref();
|
ptr->ref();
|
||||||
@ -1959,7 +1959,6 @@ void tst_QSharedPointer::threadStressTest()
|
|||||||
|
|
||||||
base.clear();
|
base.clear();
|
||||||
|
|
||||||
srand(time(NULL));
|
|
||||||
// start threads
|
// start threads
|
||||||
for (int i = 0; i < allThreads.count(); ++i)
|
for (int i = 0; i < allThreads.count(); ++i)
|
||||||
if (allThreads[i]) allThreads[i]->start();
|
if (allThreads[i]) allThreads[i]->start();
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <qimagereader.h>
|
#include <qimagereader.h>
|
||||||
#include <qlist.h>
|
#include <qlist.h>
|
||||||
#include <qmatrix.h>
|
#include <qmatrix.h>
|
||||||
|
#include <qrandom.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <qpainter.h>
|
#include <qpainter.h>
|
||||||
@ -1754,7 +1755,7 @@ void tst_QImage::smoothScale2()
|
|||||||
|
|
||||||
static inline int rand8()
|
static inline int rand8()
|
||||||
{
|
{
|
||||||
return int(256. * (qrand() / (RAND_MAX + 1.0)));
|
return QRandomGenerator::global()->bounded(256);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QImage::smoothScale3_data()
|
void tst_QImage::smoothScale3_data()
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include <qdesktopwidget.h>
|
#include <qdesktopwidget.h>
|
||||||
#endif
|
#endif
|
||||||
#include <qpixmap.h>
|
#include <qpixmap.h>
|
||||||
|
#include <qrandom.h>
|
||||||
|
|
||||||
#include <private/qdrawhelper_p.h>
|
#include <private/qdrawhelper_p.h>
|
||||||
#include <qpainter.h>
|
#include <qpainter.h>
|
||||||
@ -3052,7 +3053,7 @@ void tst_QPainter::fpe_steepSlopes_data()
|
|||||||
|
|
||||||
qreal randf()
|
qreal randf()
|
||||||
{
|
{
|
||||||
return rand() / (RAND_MAX + 1.0);
|
return QRandomGenerator::global()->bounded(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF randInRect(const QRectF &rect)
|
QPointF randInRect(const QRectF &rect)
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include <qpolygon.h>
|
#include <qpolygon.h>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <qpainter.h>
|
#include <qpainter.h>
|
||||||
|
#include <qrandom.h>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@ -423,8 +424,8 @@ void tst_QPathClipper::clip()
|
|||||||
|
|
||||||
static inline QPointF randomPointInRect(const QRectF &rect)
|
static inline QPointF randomPointInRect(const QRectF &rect)
|
||||||
{
|
{
|
||||||
qreal rx = qrand() / (RAND_MAX + 1.);
|
qreal rx = QRandomGenerator::global()->bounded(1.0);
|
||||||
qreal ry = qrand() / (RAND_MAX + 1.);
|
qreal ry = QRandomGenerator::global()->bounded(1.0);
|
||||||
|
|
||||||
return QPointF(rect.left() + rx * rect.width(),
|
return QPointF(rect.left() + rx * rect.width(),
|
||||||
rect.top() + ry * rect.height());
|
rect.top() + ry * rect.height());
|
||||||
|
@ -145,7 +145,7 @@ void tst_QTextPieceTable::insertion3()
|
|||||||
{
|
{
|
||||||
QString compare;
|
QString compare;
|
||||||
for (int i = 0; i < 20000; ++i) {
|
for (int i = 0; i < 20000; ++i) {
|
||||||
int pos = rand() % (i+1);
|
int pos = QRandomGenerator::global()->bounded(i+1);
|
||||||
QChar c((unsigned short)(i & 0xff) + 1);
|
QChar c((unsigned short)(i & 0xff) + 1);
|
||||||
QString str;
|
QString str;
|
||||||
str += c;
|
str += c;
|
||||||
@ -159,7 +159,7 @@ void tst_QTextPieceTable::insertion4()
|
|||||||
{
|
{
|
||||||
QString compare;
|
QString compare;
|
||||||
for (int i = 0; i < 20000; ++i) {
|
for (int i = 0; i < 20000; ++i) {
|
||||||
int pos = rand() % (i+1);
|
int pos = QRandomGenerator::global()->generate() % (i+1);
|
||||||
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
|
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
|
||||||
QString str;
|
QString str;
|
||||||
str += c;
|
str += c;
|
||||||
@ -178,7 +178,7 @@ void tst_QTextPieceTable::insertion5()
|
|||||||
{
|
{
|
||||||
QString compare;
|
QString compare;
|
||||||
for (int i = 0; i < 20000; ++i) {
|
for (int i = 0; i < 20000; ++i) {
|
||||||
int pos = rand() % (i+1);
|
int pos = QRandomGenerator::global()->generate() % (i+1);
|
||||||
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
|
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
|
||||||
QString str;
|
QString str;
|
||||||
str += c;
|
str += c;
|
||||||
@ -236,8 +236,8 @@ void tst_QTextPieceTable::removal3()
|
|||||||
QString compare;
|
QString compare;
|
||||||
int l = 0;
|
int l = 0;
|
||||||
for (int i = 0; i < 20000; ++i) {
|
for (int i = 0; i < 20000; ++i) {
|
||||||
bool remove = l && (rand() % 2);
|
bool remove = l && (QRandomGenerator::global()->bounded(2));
|
||||||
int pos = rand() % (remove ? l : (l+1));
|
int pos = QRandomGenerator::global()->bounded(remove ? l : (l+1));
|
||||||
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
|
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
|
||||||
QString str;
|
QString str;
|
||||||
str += c;
|
str += c;
|
||||||
@ -263,8 +263,8 @@ void tst_QTextPieceTable::removal4()
|
|||||||
QString compare;
|
QString compare;
|
||||||
int l = 0;
|
int l = 0;
|
||||||
for (int i = 0; i < 20000; ++i) {
|
for (int i = 0; i < 20000; ++i) {
|
||||||
bool remove = l && (rand() % 2);
|
bool remove = l && (QRandomGenerator::global()->bounded(2));
|
||||||
int pos = (l > 1) ? rand() % (remove ? l-1 : l) : 0;
|
int pos = (l > 1) ? QRandomGenerator::global()->bounded(remove ? l-1 : l) : 0;
|
||||||
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
|
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
|
||||||
QString str;
|
QString str;
|
||||||
if (c != 'a') {
|
if (c != 'a') {
|
||||||
@ -472,13 +472,12 @@ void tst_QTextPieceTable::undoRedo10()
|
|||||||
|
|
||||||
void tst_QTextPieceTable::undoRedo11()
|
void tst_QTextPieceTable::undoRedo11()
|
||||||
{
|
{
|
||||||
srand(3);
|
|
||||||
const int loops = 20;
|
const int loops = 20;
|
||||||
QString compare;
|
QString compare;
|
||||||
int l = 0;
|
int l = 0;
|
||||||
for (int i = 0; i < loops; ++i) {
|
for (int i = 0; i < loops; ++i) {
|
||||||
bool remove = l && (rand() % 2);
|
bool remove = l && (QRandomGenerator::global()->bounded(2));
|
||||||
int pos = (l > 1) ? rand() % (remove ? l-1 : l) : 0;
|
int pos = (l > 1) ? QRandomGenerator::global()->bounded(remove ? l-1 : l) : 0;
|
||||||
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
|
QChar c((unsigned short)((i % 26) + (i>25?'A':'a')));
|
||||||
QString str;
|
QString str;
|
||||||
str += c;
|
str += c;
|
||||||
|
@ -273,13 +273,13 @@ void tst_Hpack::bitstreamCompression()
|
|||||||
std::vector<uchar> buffer;
|
std::vector<uchar> buffer;
|
||||||
BitOStream out(buffer);
|
BitOStream out(buffer);
|
||||||
for (unsigned i = 0; i < nValues; ++i) {
|
for (unsigned i = 0; i < nValues; ++i) {
|
||||||
const bool isString = std::rand() % 1000 > 500;
|
const bool isString = QRandomGenerator::global()->bounded(1000) > 500;
|
||||||
isA.push_back(isString);
|
isA.push_back(isString);
|
||||||
if (!isString) {
|
if (!isString) {
|
||||||
integers.push_back(std::rand() % 1000);
|
integers.push_back(QRandomGenerator::global()->bounded(1000u));
|
||||||
out.write(integers.back());
|
out.write(integers.back());
|
||||||
} else {
|
} else {
|
||||||
const auto start = std::rand() % (bytes.length() / 2);
|
const auto start = QRandomGenerator::global()->bounded(uint(bytes.length()) / 2);
|
||||||
auto end = start * 2;
|
auto end = start * 2;
|
||||||
if (!end)
|
if (!end)
|
||||||
end = bytes.length() / 2;
|
end = bytes.length() / 2;
|
||||||
@ -287,7 +287,7 @@ void tst_Hpack::bitstreamCompression()
|
|||||||
const auto &s = strings.back();
|
const auto &s = strings.back();
|
||||||
totalStringBytes += s.size();
|
totalStringBytes += s.size();
|
||||||
QByteArray data(s.c_str(), int(s.size()));
|
QByteArray data(s.c_str(), int(s.size()));
|
||||||
const bool compressed(std::rand() % 1000 > 500);
|
const bool compressed(QRandomGenerator::global()->bounded(1000) > 500);
|
||||||
out.write(data, compressed);
|
out.write(data, compressed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -442,8 +442,8 @@ void tst_Hpack::lookupTableDynamic()
|
|||||||
// Strings are repeating way too often, I want to
|
// Strings are repeating way too often, I want to
|
||||||
// have at least some items really evicted and not found,
|
// have at least some items really evicted and not found,
|
||||||
// therefore these weird dances with start/len.
|
// therefore these weird dances with start/len.
|
||||||
const quint32 start = std::rand() % (dataSize - 10);
|
const quint32 start = QRandomGenerator::global()->bounded(dataSize - 10);
|
||||||
quint32 len = std::rand() % (dataSize - start);
|
quint32 len = QRandomGenerator::global()->bounded(dataSize - start);
|
||||||
if (!len)
|
if (!len)
|
||||||
len = 1;
|
len = 1;
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ void tst_Http2::multipleRequests()
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < nRequests; ++i)
|
for (int i = 0; i < nRequests; ++i)
|
||||||
sendRequest(i, priorities[std::rand() % 3]);
|
sendRequest(i, priorities[QRandomGenerator::global()->bounded(3)]);
|
||||||
|
|
||||||
runEventLoop();
|
runEventLoop();
|
||||||
|
|
||||||
|
@ -276,8 +276,7 @@ void tst_QFtp::init()
|
|||||||
|
|
||||||
inFileDirExistsFunction = false;
|
inFileDirExistsFunction = false;
|
||||||
|
|
||||||
srand(time(0));
|
uniqueExtension = QString::number((quintptr)this) + QString::number(QRandomGenerator::global()->generate())
|
||||||
uniqueExtension = QString::number((quintptr)this) + QString::number(rand())
|
|
||||||
+ QString::number((qulonglong)time(0));
|
+ QString::number((qulonglong)time(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
#include <QtNetwork/QtNetwork>
|
#include <QtNetwork/QtNetwork>
|
||||||
#include <qnetworkdiskcache.h>
|
#include <qnetworkdiskcache.h>
|
||||||
|
#include <qrandom.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -693,25 +694,25 @@ public:
|
|||||||
|
|
||||||
if (write) {
|
if (write) {
|
||||||
QNetworkCacheMetaData m;
|
QNetworkCacheMetaData m;
|
||||||
if (qrand() % 2 == 0)
|
if (QRandomGenerator::global()->bounded(2) == 0)
|
||||||
m = metaData;
|
m = metaData;
|
||||||
else
|
else
|
||||||
m = metaData2;
|
m = metaData2;
|
||||||
|
|
||||||
if (qrand() % 20 == 1) {
|
if (QRandomGenerator::global()->bounded(20) == 1) {
|
||||||
//qDebug() << "write update";
|
//qDebug() << "write update";
|
||||||
cache.updateMetaData(m);
|
cache.updateMetaData(m);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QIODevice *device = cache.prepare(m);
|
QIODevice *device = cache.prepare(m);
|
||||||
if (qrand() % 20 == 1) {
|
if (QRandomGenerator::global()->bounded(20) == 1) {
|
||||||
//qDebug() << "write remove";
|
//qDebug() << "write remove";
|
||||||
cache.remove(url);
|
cache.remove(url);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QVERIFY(device);
|
QVERIFY(device);
|
||||||
if (qrand() % 2 == 0)
|
if (QRandomGenerator::global()->bounded(2) == 0)
|
||||||
device->write(longString);
|
device->write(longString);
|
||||||
else
|
else
|
||||||
device->write(longString2);
|
device->write(longString2);
|
||||||
@ -740,9 +741,9 @@ public:
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (qrand() % 5 == 1)
|
if (QRandomGenerator::global()->bounded(5) == 1)
|
||||||
cache.remove(url);
|
cache.remove(url);
|
||||||
if (qrand() % 5 == 1)
|
if (QRandomGenerator::global()->bounded(5) == 1)
|
||||||
cache.clear();
|
cache.clear();
|
||||||
sleep(0);
|
sleep(0);
|
||||||
}
|
}
|
||||||
@ -791,7 +792,6 @@ void tst_QNetworkDiskCache::sync()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QTime midnight(0, 0, 0);
|
QTime midnight(0, 0, 0);
|
||||||
qsrand(midnight.secsTo(QTime::currentTime()));
|
|
||||||
Runner reader(tempDir.path());
|
Runner reader(tempDir.path());
|
||||||
reader.dt = QDateTime::currentDateTime();
|
reader.dt = QDateTime::currentDateTime();
|
||||||
reader.write = false;
|
reader.write = false;
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
#include <QtCore/QEventLoop>
|
#include <QtCore/QEventLoop>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
|
#include <QtCore/QRandomGenerator>
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
#include <QtCore/QScopedPointer>
|
#include <QtCore/QScopedPointer>
|
||||||
#include <QtCore/QTemporaryFile>
|
#include <QtCore/QTemporaryFile>
|
||||||
@ -120,12 +121,11 @@ class tst_QNetworkReply: public QObject
|
|||||||
static QString createUniqueExtension()
|
static QString createUniqueExtension()
|
||||||
{
|
{
|
||||||
if (!seedCreated) {
|
if (!seedCreated) {
|
||||||
qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) + QCoreApplication::applicationPid());
|
|
||||||
seedCreated = true; // not thread-safe, but who cares
|
seedCreated = true; // not thread-safe, but who cares
|
||||||
}
|
}
|
||||||
return QString::number(QTime(0, 0, 0).msecsTo(QTime::currentTime()))
|
return QString::number(QTime(0, 0, 0).msecsTo(QTime::currentTime()))
|
||||||
+ QLatin1Char('-') + QString::number(QCoreApplication::applicationPid())
|
+ QLatin1Char('-') + QString::number(QCoreApplication::applicationPid())
|
||||||
+ QLatin1Char('-') + QString::number(qrand());
|
+ QLatin1Char('-') + QString::number(QRandomGenerator::global()->generate());
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString tempRedirectReplyStr() {
|
static QString tempRedirectReplyStr() {
|
||||||
@ -4852,7 +4852,7 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress()
|
|||||||
// server send the data much faster than expected.
|
// server send the data much faster than expected.
|
||||||
// So better provide random data that cannot be compressed.
|
// So better provide random data that cannot be compressed.
|
||||||
for (int i = 0; i < wantedSize; ++i)
|
for (int i = 0; i < wantedSize; ++i)
|
||||||
sourceFile += (char)qrand();
|
sourceFile += (char)QRandomGenerator::global()->generate();
|
||||||
|
|
||||||
// emulate a minimal https server
|
// emulate a minimal https server
|
||||||
SslServer server;
|
SslServer server;
|
||||||
@ -4932,7 +4932,7 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp()
|
|||||||
// server send the data much faster than expected.
|
// server send the data much faster than expected.
|
||||||
// So better provide random data that cannot be compressed.
|
// So better provide random data that cannot be compressed.
|
||||||
for (int i = 0; i < wantedSize; ++i)
|
for (int i = 0; i < wantedSize; ++i)
|
||||||
testData += (char)qrand();
|
testData += (char)QRandomGenerator::global()->generate();
|
||||||
|
|
||||||
QByteArray httpResponse = QByteArray("HTTP/1.0 200 OK\r\nContent-Length: ");
|
QByteArray httpResponse = QByteArray("HTTP/1.0 200 OK\r\nContent-Length: ");
|
||||||
httpResponse += QByteArray::number(testData.size());
|
httpResponse += QByteArray::number(testData.size());
|
||||||
@ -8748,7 +8748,7 @@ public slots:
|
|||||||
m_receivedData += data;
|
m_receivedData += data;
|
||||||
if (!m_parsedHeaders && m_receivedData.contains("\r\n\r\n")) {
|
if (!m_parsedHeaders && m_receivedData.contains("\r\n\r\n")) {
|
||||||
m_parsedHeaders = true;
|
m_parsedHeaders = true;
|
||||||
QTimer::singleShot(qrand()%60, this, SLOT(closeDelayed())); // simulate random network latency
|
QTimer::singleShot(QRandomGenerator::global()->bounded(60), this, SLOT(closeDelayed())); // simulate random network latency
|
||||||
// This server simulates a web server connection closing, e.g. because of Apaches MaxKeepAliveRequests or KeepAliveTimeout
|
// This server simulates a web server connection closing, e.g. because of Apaches MaxKeepAliveRequests or KeepAliveTimeout
|
||||||
// In this case QNAM needs to re-send the upload data but it had a bug which then corrupts the upload
|
// In this case QNAM needs to re-send the upload data but it had a bug which then corrupts the upload
|
||||||
// This test catches that.
|
// This test catches that.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2016 The Qt Company Ltd.
|
||||||
** Copyright (C) 2016 Intel Corporation.
|
** Copyright (C) 2017 Intel Corporation.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -57,6 +57,7 @@
|
|||||||
#if QT_CONFIG(process)
|
#if QT_CONFIG(process)
|
||||||
# include <QProcess>
|
# include <QProcess>
|
||||||
#endif
|
#endif
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
@ -305,8 +306,6 @@ public:
|
|||||||
tst_QTcpSocket::tst_QTcpSocket()
|
tst_QTcpSocket::tst_QTcpSocket()
|
||||||
: firstFailName("qt-test-server-first-fail")
|
: firstFailName("qt-test-server-first-fail")
|
||||||
{
|
{
|
||||||
qsrand(time(NULL));
|
|
||||||
|
|
||||||
tmpSocket = 0;
|
tmpSocket = 0;
|
||||||
|
|
||||||
//This code relates to the socketsConstructedBeforeEventLoop test case
|
//This code relates to the socketsConstructedBeforeEventLoop test case
|
||||||
@ -581,8 +580,7 @@ void tst_QTcpSocket::bind()
|
|||||||
// try to get a random port number
|
// try to get a random port number
|
||||||
// we do this to ensure we're not trying to bind to the same port as we've just used in
|
// we do this to ensure we're not trying to bind to the same port as we've just used in
|
||||||
// a previous run - race condition with the OS actually freeing the port
|
// a previous run - race condition with the OS actually freeing the port
|
||||||
Q_STATIC_ASSERT(RAND_MAX > 1024);
|
port = QRandomGenerator::global()->generate() & USHRT_MAX;
|
||||||
port = qrand() & USHRT_MAX;
|
|
||||||
if (port < 1024)
|
if (port < 1024)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ public:
|
|||||||
|
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
p.fillRect(rect(), QColor(rand() % 256, rand() % 256, rand() % 256));
|
p.fillRect(rect(), QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
|
||||||
p.setPen(Qt::red);
|
p.setPen(Qt::red);
|
||||||
p.setFont(QFont("SansSerif", 24));
|
p.setFont(QFont("SansSerif", 24));
|
||||||
p.drawText(rect(), Qt::AlignCenter, "This is an autotest");
|
p.drawText(rect(), Qt::AlignCenter, "This is an autotest");
|
||||||
@ -229,7 +229,7 @@ public:
|
|||||||
int height = 300;
|
int height = 300;
|
||||||
QImage image(width, height, QImage::Format_RGB32);
|
QImage image(width, height, QImage::Format_RGB32);
|
||||||
QPainter p(&image);
|
QPainter p(&image);
|
||||||
p.fillRect(image.rect(), QColor(rand() % 256, rand() % 256, rand() % 256));
|
p.fillRect(image.rect(), QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
|
||||||
p.setPen(Qt::red);
|
p.setPen(Qt::red);
|
||||||
p.setFont(QFont("SansSerif", 24));
|
p.setFont(QFont("SansSerif", 24));
|
||||||
p.drawText(image.rect(), Qt::AlignCenter, "This is an autotest");
|
p.drawText(image.rect(), Qt::AlignCenter, "This is an autotest");
|
||||||
@ -271,7 +271,7 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void receiveImage(const QImage &image) {
|
void receiveImage(const QImage &image) {
|
||||||
m_images << image;
|
m_images << image;
|
||||||
m_positions << QPoint(-rand() % width() / 2, -rand() % height() / 2);
|
m_positions << QPoint(-QRandomGenerator::global()->bounded(width() / 2), -QRandomGenerator::global()->bounded(height() / 2));
|
||||||
|
|
||||||
m_semaphore->release(1);
|
m_semaphore->release(1);
|
||||||
|
|
||||||
@ -326,7 +326,7 @@ void tst_QGLThreads::textureUploadInThread()
|
|||||||
if that works, we're in good shape..
|
if that works, we're in good shape..
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline float qrandom() { return (rand() % 100) / 100.f; }
|
static inline float qrandom() { return (QRandomGenerator::global()->bounded(100)) / 100.f; }
|
||||||
|
|
||||||
void renderAScene(int w, int h)
|
void renderAScene(int w, int h)
|
||||||
{
|
{
|
||||||
@ -345,12 +345,12 @@ void renderAScene(int w, int h)
|
|||||||
|
|
||||||
for (int i=0; i<1000; ++i) {
|
for (int i=0; i<1000; ++i) {
|
||||||
GLfloat pos[] = {
|
GLfloat pos[] = {
|
||||||
(rand() % 100) / 100.f,
|
(QRandomGenerator::global()->bounded(100)) / 100.f,
|
||||||
(rand() % 100) / 100.f,
|
(QRandomGenerator::global()->bounded(100)) / 100.f,
|
||||||
(rand() % 100) / 100.f,
|
(QRandomGenerator::global()->bounded(100)) / 100.f,
|
||||||
(rand() % 100) / 100.f,
|
(QRandomGenerator::global()->bounded(100)) / 100.f,
|
||||||
(rand() % 100) / 100.f,
|
(QRandomGenerator::global()->bounded(100)) / 100.f,
|
||||||
(rand() % 100) / 100.f
|
(QRandomGenerator::global()->bounded(100)) / 100.f
|
||||||
};
|
};
|
||||||
|
|
||||||
funcs->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, pos);
|
funcs->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, pos);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2016 The Qt Company Ltd.
|
||||||
** Copyright (C) 2016 Intel Corporation.
|
** Copyright (C) 2017 Intel Corporation.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -802,7 +802,7 @@ void tst_Compiler::cxx11_auto_type()
|
|||||||
QSKIP("Compiler does not support C++11 feature");
|
QSKIP("Compiler does not support C++11 feature");
|
||||||
#else
|
#else
|
||||||
auto i = 1;
|
auto i = 1;
|
||||||
auto x = qrand();
|
auto x = QRandomGenerator::global()->generate();
|
||||||
auto l = 1L;
|
auto l = 1L;
|
||||||
auto s = QStringLiteral("Hello World");
|
auto s = QStringLiteral("Hello World");
|
||||||
|
|
||||||
@ -851,8 +851,8 @@ void tst_Compiler::cxx11_decltype()
|
|||||||
#ifndef Q_COMPILER_DECLTYPE
|
#ifndef Q_COMPILER_DECLTYPE
|
||||||
QSKIP("Compiler does not support C++11 feature");
|
QSKIP("Compiler does not support C++11 feature");
|
||||||
#else
|
#else
|
||||||
decltype(qrand()) i = 0;
|
decltype(QRandomGenerator::global()->generate()) i = 0;
|
||||||
QCOMPARE(i, 0);
|
QCOMPARE(i, 0U);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1549,7 +1549,7 @@ void tst_Compiler::runtimeArrays()
|
|||||||
#if __cpp_runtime_arrays-0 < 201304
|
#if __cpp_runtime_arrays-0 < 201304
|
||||||
QSKIP("Compiler does not support this C++14 feature");
|
QSKIP("Compiler does not support this C++14 feature");
|
||||||
#else
|
#else
|
||||||
int i[qrand() & 0x1f];
|
int i[QRandomGenerator::global()->generate() & 0x1f];
|
||||||
Q_UNUSED(i);
|
Q_UNUSED(i);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <QtNetwork/QtNetwork>
|
#include <QtNetwork/QtNetwork>
|
||||||
#include <QtCore/QDateTime>
|
#include <QtCore/QDateTime>
|
||||||
#include <QtCore/QTextStream>
|
#include <QtCore/QTextStream>
|
||||||
|
#include <QtCore/QRandomGenerator>
|
||||||
#include <QtCore/QStandardPaths>
|
#include <QtCore/QStandardPaths>
|
||||||
#include <QtCore/private/qiodevice_p.h>
|
#include <QtCore/private/qiodevice_p.h>
|
||||||
|
|
||||||
@ -538,7 +539,7 @@ void tst_NetworkSelfTest::imapServer()
|
|||||||
void tst_NetworkSelfTest::httpServer()
|
void tst_NetworkSelfTest::httpServer()
|
||||||
{
|
{
|
||||||
QByteArray uniqueExtension = QByteArray::number((qulonglong)this) +
|
QByteArray uniqueExtension = QByteArray::number((qulonglong)this) +
|
||||||
QByteArray::number((qulonglong)qrand()) +
|
QByteArray::number((qulonglong)QRandomGenerator::global()->generate()) +
|
||||||
QByteArray::number(QDateTime::currentSecsSinceEpoch());
|
QByteArray::number(QDateTime::currentSecsSinceEpoch());
|
||||||
|
|
||||||
netChat(80, QList<Chat>()
|
netChat(80, QList<Chat>()
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
#include <qlineedit.h>
|
#include <qlineedit.h>
|
||||||
#include <qlayout.h>
|
#include <qlayout.h>
|
||||||
#include <qmenu.h>
|
#include <qmenu.h>
|
||||||
|
#include <qrandom.h>
|
||||||
#include "../../../../../src/widgets/dialogs/qsidebar_p.h"
|
#include "../../../../../src/widgets/dialogs/qsidebar_p.h"
|
||||||
#include "../../../../../src/widgets/dialogs/qfilesystemmodel_p.h"
|
#include "../../../../../src/widgets/dialogs/qfilesystemmodel_p.h"
|
||||||
#include "../../../../../src/widgets/dialogs/qfiledialog_p.h"
|
#include "../../../../../src/widgets/dialogs/qfiledialog_p.h"
|
||||||
@ -1196,7 +1197,7 @@ void tst_QFileDialog2::QTBUG6558_showDirsOnly()
|
|||||||
{
|
{
|
||||||
const QString tempPath = tempDir.path();
|
const QString tempPath = tempDir.path();
|
||||||
QDir dirTemp(tempPath);
|
QDir dirTemp(tempPath);
|
||||||
const QString tempName = QLatin1String("showDirsOnly.") + QString::number(qrand());
|
const QString tempName = QLatin1String("showDirsOnly.") + QString::number(QRandomGenerator::global()->generate());
|
||||||
dirTemp.mkdir(tempName);
|
dirTemp.mkdir(tempName);
|
||||||
dirTemp.cd(tempName);
|
dirTemp.cd(tempName);
|
||||||
QTRY_VERIFY(dirTemp.exists());
|
QTRY_VERIFY(dirTemp.exists());
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <private/qgraphicsitem_p.h>
|
#include <private/qgraphicsitem_p.h>
|
||||||
#include <private/qgraphicsview_p.h>
|
#include <private/qgraphicsview_p.h>
|
||||||
#include <private/qgraphicsscene_p.h>
|
#include <private/qgraphicsscene_p.h>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QStyleOptionGraphicsItem>
|
#include <QStyleOptionGraphicsItem>
|
||||||
#include <QAbstractTextDocumentLayout>
|
#include <QAbstractTextDocumentLayout>
|
||||||
#include <QBitmap>
|
#include <QBitmap>
|
||||||
@ -3595,12 +3596,12 @@ void tst_QGraphicsItem::group()
|
|||||||
QList<QGraphicsItem *> newItems;
|
QList<QGraphicsItem *> newItems;
|
||||||
for (int i = 0; i < 100; ++i) {
|
for (int i = 0; i < 100; ++i) {
|
||||||
QGraphicsItem *item = scene.addRect(QRectF(-25, -25, 50, 50), QPen(Qt::black, 0),
|
QGraphicsItem *item = scene.addRect(QRectF(-25, -25, 50, 50), QPen(Qt::black, 0),
|
||||||
QBrush(QColor(rand() % 255, rand() % 255,
|
QBrush(QColor(QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255),
|
||||||
rand() % 255, rand() % 255)));
|
QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255))));
|
||||||
newItems << item;
|
newItems << item;
|
||||||
item->setPos(-1000 + rand() % 2000,
|
item->setPos(-1000 + QRandomGenerator::global()->bounded(2000),
|
||||||
-1000 + rand() % 2000);
|
-1000 + QRandomGenerator::global()->bounded(2000));
|
||||||
item->setTransform(QTransform().rotate(rand() % 90), true);
|
item->setTransform(QTransform().rotate(QRandomGenerator::global()->bounded(90)), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
view.fitInView(scene.itemsBoundingRect());
|
view.fitInView(scene.itemsBoundingRect());
|
||||||
@ -4143,8 +4144,8 @@ void tst_QGraphicsItem::ensureVisible()
|
|||||||
|
|
||||||
for (int x = -100; x < 100; x += 25) {
|
for (int x = -100; x < 100; x += 25) {
|
||||||
for (int y = -100; y < 100; y += 25) {
|
for (int y = -100; y < 100; y += 25) {
|
||||||
int xmargin = rand() % 75;
|
int xmargin = QRandomGenerator::global()->bounded(75);
|
||||||
int ymargin = rand() % 75;
|
int ymargin = QRandomGenerator::global()->bounded(75);
|
||||||
item->ensureVisible(x, y, 25, 25, xmargin, ymargin);
|
item->ensureVisible(x, y, 25, 25, xmargin, ymargin);
|
||||||
QApplication::processEvents();
|
QApplication::processEvents();
|
||||||
|
|
||||||
@ -7137,7 +7138,7 @@ public:
|
|||||||
: QGraphicsRectItem(QRectF(-10, -10, 20, 20))
|
: QGraphicsRectItem(QRectF(-10, -10, 20, 20))
|
||||||
{
|
{
|
||||||
setPen(QPen(Qt::black, 0));
|
setPen(QPen(Qt::black, 0));
|
||||||
setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
|
setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QTransform x;
|
QTransform x;
|
||||||
|
@ -1507,10 +1507,10 @@ void tst_QGraphicsScene::mouseGrabberItem()
|
|||||||
QCOMPARE(scene.mouseGrabberItem(), topMostItem);
|
QCOMPARE(scene.mouseGrabberItem(), topMostItem);
|
||||||
|
|
||||||
// Geometrical changes should not affect the mouse grabber.
|
// Geometrical changes should not affect the mouse grabber.
|
||||||
item->setZValue(rand() % 500);
|
item->setZValue(QRandomGenerator::global()->bounded(500));
|
||||||
item2->setZValue(rand() % 500);
|
item2->setZValue(QRandomGenerator::global()->bounded(500));
|
||||||
item->setPos(rand() % 50000, rand() % 50000);
|
item->setPos(QRandomGenerator::global()->bounded(50000), QRandomGenerator::global()->bounded(50000));
|
||||||
item2->setPos(rand() % 50000, rand() % 50000);
|
item2->setPos(QRandomGenerator::global()->bounded(50000), QRandomGenerator::global()->bounded(50000));
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
|
QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
|
||||||
@ -3424,7 +3424,7 @@ void tst_QGraphicsScene::task139710_bspTreeCrash()
|
|||||||
// add 1000 more items - the BSP tree is now resized
|
// add 1000 more items - the BSP tree is now resized
|
||||||
for (int i = 0; i < 1000; ++i) {
|
for (int i = 0; i < 1000; ++i) {
|
||||||
QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 200, 200));
|
QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 200, 200));
|
||||||
item->setPos(qrand() % 10000, qrand() % 10000);
|
item->setPos(QRandomGenerator::global()->bounded(10000), QRandomGenerator::global()->bounded(10000));
|
||||||
}
|
}
|
||||||
|
|
||||||
// trigger delayed item indexing for the first 1000 items
|
// trigger delayed item indexing for the first 1000 items
|
||||||
@ -3433,7 +3433,7 @@ void tst_QGraphicsScene::task139710_bspTreeCrash()
|
|||||||
// add 1000 more items - the BSP tree is now resized
|
// add 1000 more items - the BSP tree is now resized
|
||||||
for (int i = 0; i < 1000; ++i) {
|
for (int i = 0; i < 1000; ++i) {
|
||||||
QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 200, 200));
|
QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 200, 200));
|
||||||
item->setPos(qrand() % 10000, qrand() % 10000);
|
item->setPos(QRandomGenerator::global()->bounded(10000), QRandomGenerator::global()->bounded(10000));
|
||||||
}
|
}
|
||||||
|
|
||||||
// get items from the BSP tree and use them. there was junk in the tree
|
// get items from the BSP tree and use them. there was junk in the tree
|
||||||
@ -3543,15 +3543,15 @@ void tst_QGraphicsScene::sorting()
|
|||||||
QGraphicsRectItem *c_2_1 = new QGraphicsRectItem(0, 0, 30, 30, c_2);
|
QGraphicsRectItem *c_2_1 = new QGraphicsRectItem(0, 0, 30, 30, c_2);
|
||||||
QGraphicsRectItem *c_2_1_1 = new QGraphicsRectItem(0, 0, 20, 20, c_2_1);
|
QGraphicsRectItem *c_2_1_1 = new QGraphicsRectItem(0, 0, 20, 20, c_2_1);
|
||||||
QGraphicsRectItem *c_2_2 = new QGraphicsRectItem(0, 0, 30, 30, c_2);
|
QGraphicsRectItem *c_2_2 = new QGraphicsRectItem(0, 0, 30, 30, c_2);
|
||||||
t_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
|
t_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
|
||||||
c_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
|
c_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
|
||||||
c_1_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
|
c_1_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
|
||||||
c_1_1_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
|
c_1_1_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
|
||||||
c_1_2->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
|
c_1_2->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
|
||||||
c_2->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
|
c_2->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
|
||||||
c_2_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
|
c_2_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
|
||||||
c_2_1_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
|
c_2_1_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
|
||||||
c_2_2->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256));
|
c_2_2->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)));
|
||||||
|
|
||||||
c_1->setPos(23, 18);
|
c_1->setPos(23, 18);
|
||||||
c_1_1->setPos(24, 28);
|
c_1_1->setPos(24, 28);
|
||||||
|
@ -30,16 +30,6 @@
|
|||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
#include <QtCore/QtCore>
|
#include <QtCore/QtCore>
|
||||||
#include "viewstotest.cpp"
|
#include "viewstotest.cpp"
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#if defined(Q_OS_UNIX) || defined(Q_OS_WIN)
|
|
||||||
#include <time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
|
||||||
# define random rand
|
|
||||||
# define srandom srand
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
See viewstotest.cpp for instructions on how to have your view tested with these tests.
|
See viewstotest.cpp for instructions on how to have your view tested with these tests.
|
||||||
@ -410,13 +400,15 @@ void touch(QWidget *widget, Qt::KeyboardModifier modifier, Qt::Key keyPress){
|
|||||||
int width = widget->width();
|
int width = widget->width();
|
||||||
int height = widget->height();
|
int height = widget->height();
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i) {
|
||||||
QTest::mouseClick(widget, Qt::LeftButton, modifier, QPoint(random() % width, random() % height));
|
QTest::mouseClick(widget, Qt::LeftButton, modifier,
|
||||||
QTest::mouseDClick(widget, Qt::LeftButton, modifier, QPoint(random() % width, random() % height));
|
QPoint(QRandomGenerator::global()->bounded(width), QRandomGenerator::global()->bounded(height)));
|
||||||
QPoint press(random() % width, random() % height);
|
QTest::mouseDClick(widget, Qt::LeftButton, modifier,
|
||||||
QPoint releasePoint(random() % width, random() % height);
|
QPoint(QRandomGenerator::global()->bounded(width), QRandomGenerator::global()->bounded(height)));
|
||||||
|
QPoint press(QRandomGenerator::global()->bounded(width), QRandomGenerator::global()->bounded(height));
|
||||||
|
QPoint releasePoint(QRandomGenerator::global()->bounded(width), QRandomGenerator::global()->bounded(height));
|
||||||
QTest::mousePress(widget, Qt::LeftButton, modifier, press);
|
QTest::mousePress(widget, Qt::LeftButton, modifier, press);
|
||||||
QTest::mouseMove(widget, releasePoint);
|
QTest::mouseMove(widget, releasePoint);
|
||||||
if (random() % 1 == 0)
|
if (QRandomGenerator::global()->bounded(1) == 0)
|
||||||
QTest::mouseRelease(widget, Qt::LeftButton, 0, releasePoint);
|
QTest::mouseRelease(widget, Qt::LeftButton, 0, releasePoint);
|
||||||
else
|
else
|
||||||
QTest::mouseRelease(widget, Qt::LeftButton, modifier, releasePoint);
|
QTest::mouseRelease(widget, Qt::LeftButton, modifier, releasePoint);
|
||||||
@ -443,7 +435,6 @@ void tst_QItemView::spider()
|
|||||||
view->setModel(treeModel);
|
view->setModel(treeModel);
|
||||||
view->show();
|
view->show();
|
||||||
QVERIFY(QTest::qWaitForWindowActive(view));
|
QVERIFY(QTest::qWaitForWindowActive(view));
|
||||||
srandom(time(0));
|
|
||||||
touch(view->viewport(), Qt::NoModifier, Qt::Key_Left);
|
touch(view->viewport(), Qt::NoModifier, Qt::Key_Left);
|
||||||
touch(view->viewport(), Qt::ShiftModifier, Qt::Key_Enter);
|
touch(view->viewport(), Qt::ShiftModifier, Qt::Key_Enter);
|
||||||
touch(view->viewport(), Qt::ControlModifier, Qt::Key_Backspace);
|
touch(view->viewport(), Qt::ControlModifier, Qt::Key_Backspace);
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
#include <qcalendarwidget.h>
|
#include <qcalendarwidget.h>
|
||||||
#include <qmainwindow.h>
|
#include <qmainwindow.h>
|
||||||
#include <qdockwidget.h>
|
#include <qdockwidget.h>
|
||||||
|
#include <qrandom.h>
|
||||||
#include <qtoolbar.h>
|
#include <qtoolbar.h>
|
||||||
#include <qtoolbutton.h>
|
#include <qtoolbutton.h>
|
||||||
#include <QtGui/qpaintengine.h>
|
#include <QtGui/qpaintengine.h>
|
||||||
@ -9826,7 +9827,7 @@ void tst_QWidget::grab()
|
|||||||
for (int row = 0; row < image.height(); ++row) {
|
for (int row = 0; row < image.height(); ++row) {
|
||||||
QRgb *line = reinterpret_cast<QRgb *>(image.scanLine(row));
|
QRgb *line = reinterpret_cast<QRgb *>(image.scanLine(row));
|
||||||
for (int col = 0; col < image.width(); ++col)
|
for (int col = 0; col < image.width(); ++col)
|
||||||
line[col] = qRgba(rand() & 255, row, col, opaque ? 255 : 127);
|
line[col] = qRgba(QRandomGenerator::global()->bounded(255), row, col, opaque ? 255 : 127);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPalette pal = widget.palette();
|
QPalette pal = widget.palette();
|
||||||
|
@ -43,10 +43,6 @@
|
|||||||
#include <private/qapplication_p.h>
|
#include <private/qapplication_p.h>
|
||||||
#include "qclipboard.h"
|
#include "qclipboard.h"
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
#include <cstdlib> // For the random function.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <qlineedit.h>
|
#include <qlineedit.h>
|
||||||
#include <private/qlineedit_p.h>
|
#include <private/qlineedit_p.h>
|
||||||
#include <private/qwidgetlinecontrol_p.h>
|
#include <private/qwidgetlinecontrol_p.h>
|
||||||
@ -1949,17 +1945,7 @@ void tst_QLineEdit::noCursorBlinkWhenReadOnly()
|
|||||||
static void figureOutProperKey(Qt::Key &key, Qt::KeyboardModifiers &pressState)
|
static void figureOutProperKey(Qt::Key &key, Qt::KeyboardModifiers &pressState)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
static bool tst_lineedit_randomized = false;
|
long roll = QRandomGenerator::global()->bounded(3);
|
||||||
// Mac has 3 different ways of accomplishing this (same for moving to the back)
|
|
||||||
// So I guess we should just randomly do this for now. Which may get people mad, but if
|
|
||||||
// we fail at one point, it's just a matter of setting roll to the correct value
|
|
||||||
// instead of random.
|
|
||||||
|
|
||||||
if (!tst_lineedit_randomized) {
|
|
||||||
tst_lineedit_randomized = true;
|
|
||||||
::srandom(ulong(time(0)));
|
|
||||||
}
|
|
||||||
long roll = ::random() % 3;
|
|
||||||
switch (roll) {
|
switch (roll) {
|
||||||
case 0:
|
case 0:
|
||||||
key = key == Qt::Key_Home ? Qt::Key_Up : Qt::Key_Down;
|
key = key == Qt::Key_Home ? Qt::Key_Up : Qt::Key_Down;
|
||||||
|
@ -57,7 +57,7 @@ QVector<DataType> generateData(QString dataSetType, const int length)
|
|||||||
QVector<DataType> container;
|
QVector<DataType> container;
|
||||||
if (dataSetType == "Random") {
|
if (dataSetType == "Random") {
|
||||||
for (int i = 0; i < length; ++i)
|
for (int i = 0; i < length; ++i)
|
||||||
container.append(rand());
|
container.append(QRandomGenerator::global()->generate());
|
||||||
} else if (dataSetType == "Ascending") {
|
} else if (dataSetType == "Ascending") {
|
||||||
for (int i = 0; i < length; ++i)
|
for (int i = 0; i < length; ++i)
|
||||||
container.append(i);
|
container.append(i);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 Intel Corporation.
|
** Copyright (C) 2017 Intel Corporation.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the QtCore module of the Qt Toolkit.
|
** This file is part of the QtCore module of the Qt Toolkit.
|
||||||
@ -29,6 +29,7 @@
|
|||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
@ -102,9 +103,8 @@ tst_bench_QCryptographicHash::tst_bench_QCryptographicHash()
|
|||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
qsrand(time(NULL));
|
|
||||||
for (int i = 0; i < MaxBlockSize; ++i)
|
for (int i = 0; i < MaxBlockSize; ++i)
|
||||||
blockOfData[i] = qrand();
|
blockOfData[i] = QRandomGenerator::global()->generate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
|
||||||
#include "dummydatagen.h"
|
#include "dummydatagen.h"
|
||||||
@ -65,12 +66,11 @@ DummyDataGenerator::~DummyDataGenerator()
|
|||||||
|
|
||||||
void DummyDataGenerator::Reset()
|
void DummyDataGenerator::Reset()
|
||||||
{
|
{
|
||||||
qsrand(100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DummyDataGenerator::randomPhoneNumber(QString indexNumber)
|
QString DummyDataGenerator::randomPhoneNumber(QString indexNumber)
|
||||||
{
|
{
|
||||||
int index = qrand()%m_countryCodes.count();
|
int index = QRandomGenerator::global()->bounded(m_countryCodes.count());
|
||||||
QString countryCode = m_countryCodes.at(index);
|
QString countryCode = m_countryCodes.at(index);
|
||||||
QString areaCode = QString::number(index) + QString("0").repeated(2-QString::number(index).length());
|
QString areaCode = QString::number(index) + QString("0").repeated(2-QString::number(index).length());
|
||||||
QString beginNumber = QString::number(555-index*2);
|
QString beginNumber = QString::number(555-index*2);
|
||||||
@ -84,13 +84,13 @@ QString DummyDataGenerator::randomFirstName()
|
|||||||
{
|
{
|
||||||
m_isMale = !m_isMale;
|
m_isMale = !m_isMale;
|
||||||
if (m_isMale)
|
if (m_isMale)
|
||||||
return m_firstNamesM.at(qrand()%m_firstNamesM.count());
|
return m_firstNamesM.at(QRandomGenerator::global()->bounded(m_firstNamesM.count()));
|
||||||
return m_firstNamesF.at(qrand()%m_firstNamesF.count());
|
return m_firstNamesF.at(QRandomGenerator::global()->bounded(m_firstNamesF.count()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DummyDataGenerator::randomLastName()
|
QString DummyDataGenerator::randomLastName()
|
||||||
{
|
{
|
||||||
return m_lastNames.at(qrand()%m_lastNames.count());
|
return m_lastNames.at(QRandomGenerator::global()->bounded(m_lastNames.count()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DummyDataGenerator::randomName()
|
QString DummyDataGenerator::randomName()
|
||||||
@ -101,8 +101,8 @@ QString DummyDataGenerator::randomName()
|
|||||||
QString DummyDataGenerator::randomIconItem()
|
QString DummyDataGenerator::randomIconItem()
|
||||||
{
|
{
|
||||||
QString avatar = Theme::p()->pixmapPath() + "contact_default_icon.svg";
|
QString avatar = Theme::p()->pixmapPath() + "contact_default_icon.svg";
|
||||||
if (qrand()%4) {
|
if (QRandomGenerator::global()->bounded(4)) {
|
||||||
int randVal = 1+qrand()%25;
|
int randVal = 1+QRandomGenerator::global()->bounded(25);
|
||||||
|
|
||||||
if (m_isMale && randVal > 15) {
|
if (m_isMale && randVal > 15) {
|
||||||
randVal -= 15;
|
randVal -= 15;
|
||||||
@ -118,7 +118,7 @@ QString DummyDataGenerator::randomIconItem()
|
|||||||
|
|
||||||
QString DummyDataGenerator::randomStatusItem()
|
QString DummyDataGenerator::randomStatusItem()
|
||||||
{
|
{
|
||||||
switch (qrand()%3) {
|
switch (QRandomGenerator::global()->bounded(3)) {
|
||||||
case 0: return Theme::p()->pixmapPath() + "contact_status_online.svg";
|
case 0: return Theme::p()->pixmapPath() + "contact_status_online.svg";
|
||||||
case 1: return Theme::p()->pixmapPath() + "contact_status_offline.svg";
|
case 1: return Theme::p()->pixmapPath() + "contact_status_offline.svg";
|
||||||
case 2: return Theme::p()->pixmapPath() + "contact_status_idle.svg";
|
case 2: return Theme::p()->pixmapPath() + "contact_status_idle.svg";
|
||||||
|
@ -82,7 +82,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
for (int i = 0; i < atoi(argv[1]); ++i) {
|
for (int i = 0; i < atoi(argv[1]); ++i) {
|
||||||
QGraphicsRectItem *child = scene.addRect(-5, -5, 10, 10, QPen(Qt::NoPen), QBrush(Qt::blue));
|
QGraphicsRectItem *child = scene.addRect(-5, -5, 10, 10, QPen(Qt::NoPen), QBrush(Qt::blue));
|
||||||
child->setPos(-50 + qrand() % 100, -50 + qrand() % 100);
|
child->setPos(-50 + QRandomGenerator::global()->bounded(100), -50 + QRandomGenerator::global()->bounded(100));
|
||||||
child->setParentItem(item);
|
child->setParentItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QGraphicsWidget>
|
#include <QGraphicsWidget>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
class tst_QGraphicsWidget : public QObject
|
class tst_QGraphicsWidget : public QObject
|
||||||
{
|
{
|
||||||
@ -72,7 +73,9 @@ void tst_QGraphicsWidget::move()
|
|||||||
QGraphicsView view(&scene);
|
QGraphicsView view(&scene);
|
||||||
view.show();
|
view.show();
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
widget->setPos(qrand(),qrand());
|
// truncate the random values to 24 bits to
|
||||||
|
// avoid overflowing
|
||||||
|
widget->setPos(QRandomGenerator::global()->generate() & 0xffffff, QRandomGenerator::global()->generate() & 0xffffff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QStaticText>
|
#include <QStaticText>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
class Benchmark
|
class Benchmark
|
||||||
{
|
{
|
||||||
@ -47,9 +48,9 @@ public:
|
|||||||
: m_size(size)
|
: m_size(size)
|
||||||
{
|
{
|
||||||
for (int i=0; i<16; ++i) {
|
for (int i=0; i<16; ++i) {
|
||||||
m_colors[i] = QColor::fromRgbF((rand() % 4) / 3.0,
|
m_colors[i] = QColor::fromRgbF((QRandomGenerator::global()->bounded(4)) / 3.0,
|
||||||
(rand() % 4) / 3.0,
|
(QRandomGenerator::global()->bounded(4)) / 3.0,
|
||||||
(rand() % 4) / 3.0,
|
(QRandomGenerator::global()->bounded(4)) / 3.0,
|
||||||
1);
|
1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,7 +143,7 @@ public:
|
|||||||
ImageFillRectBenchmark(int size)
|
ImageFillRectBenchmark(int size)
|
||||||
: Benchmark(QSize(size, size))
|
: Benchmark(QSize(size, size))
|
||||||
{
|
{
|
||||||
int s = rand() % 24 + 8;
|
int s = QRandomGenerator::global()->bounded(24) + 8;
|
||||||
m_content = QImage(s, s, QImage::Format_ARGB32_Premultiplied);
|
m_content = QImage(s, s, QImage::Format_ARGB32_Premultiplied);
|
||||||
QPainter p(&m_content);
|
QPainter p(&m_content);
|
||||||
p.fillRect(0, 0, s, s, Qt::white);
|
p.fillRect(0, 0, s, s, Qt::white);
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <qtest.h>
|
#include <qtest.h>
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
|
#include <QtCore/qrandom.h>
|
||||||
#include <QtNetwork/qnetworkreply.h>
|
#include <QtNetwork/qnetworkreply.h>
|
||||||
#include <QtNetwork/qnetworkrequest.h>
|
#include <QtNetwork/qnetworkrequest.h>
|
||||||
#include <QtNetwork/qnetworkaccessmanager.h>
|
#include <QtNetwork/qnetworkaccessmanager.h>
|
||||||
@ -525,7 +526,7 @@ void tst_qnetworkreply::echoPerformance()
|
|||||||
data.resize(1024*1024*10); // 10 MB
|
data.resize(1024*1024*10); // 10 MB
|
||||||
// init with garbage. needed so ssl cannot compress it in an efficient way.
|
// init with garbage. needed so ssl cannot compress it in an efficient way.
|
||||||
for (size_t i = 0; i < data.size() / sizeof(int); i++) {
|
for (size_t i = 0; i < data.size() / sizeof(int); i++) {
|
||||||
int r = qrand();
|
char r = char(QRandomGenerator::global()->generate());
|
||||||
data.data()[i*sizeof(int)] = r;
|
data.data()[i*sizeof(int)] = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class ColorWidget : public QWidget
|
|||||||
|
|
||||||
void changeColor()
|
void changeColor()
|
||||||
{
|
{
|
||||||
color.setHsv((qreal(qrand()) / RAND_MAX) * 50 + 200, s, s);
|
color.setHsv(QRandomGenerator::global()->bounded(50) + 200, s, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
@ -93,17 +94,17 @@ public:
|
|||||||
static const QString text = QLatin1String("Qt rocks!!!");
|
static const QString text = QLatin1String("Qt rocks!!!");
|
||||||
static const int textsPerPaint = 30;
|
static const int textsPerPaint = 30;
|
||||||
for (int i = 0; i < textsPerPaint; i++) {
|
for (int i = 0; i < textsPerPaint; i++) {
|
||||||
const int fontSize = 4 + (qrand() % 5);
|
const int fontSize = 4 + QRandomGenerator::global()->bounded(5);
|
||||||
const int fontWeight = (qrand() % 2) == 1 ? QFont::Normal : QFont::Bold;
|
const int fontWeight = QRandomGenerator::global()->bounded(2) == 1 ? QFont::Normal : QFont::Bold;
|
||||||
const bool fontItalic = (qrand() % 2) == 1;
|
const bool fontItalic = QRandomGenerator::global()->bounded(2) == 1;
|
||||||
const QFont font("Default", fontSize, fontWeight, fontItalic);
|
const QFont font("Default", fontSize, fontWeight, fontItalic);
|
||||||
p.setFont(font);
|
p.setFont(font);
|
||||||
p.setPen(QColor::fromHsv(qrand() % 359, 155 + qrand() % 100,
|
p.setPen(QColor::fromHsv(QRandomGenerator::global()->bounded(359), 155 + QRandomGenerator::global()->bounded(100),
|
||||||
155 + qrand() % 100, 100 + qrand() % 155));
|
155 + QRandomGenerator::global()->bounded(100), 100 + QRandomGenerator::global()->bounded(155)));
|
||||||
const QSize textSize(p.fontMetrics().boundingRect(text).size());
|
const QSize textSize(p.fontMetrics().boundingRect(text).size());
|
||||||
const QPoint position(
|
const QPoint position(
|
||||||
-textSize.width() / 2 + (qrand() % size.width()),
|
-textSize.width() / 2 + QRandomGenerator::global()->bounded(size.width()),
|
||||||
textSize.height() / 2 + (qrand() % size.height()));
|
textSize.height() / 2 + QRandomGenerator::global()->bounded(size.height()));
|
||||||
p.drawText(position, text);
|
p.drawText(position, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,8 +127,8 @@ public:
|
|||||||
|
|
||||||
QString text;
|
QString text;
|
||||||
for (int i = 0; i < piecesPerPaint; ++i) {
|
for (int i = 0; i < piecesPerPaint; ++i) {
|
||||||
QString piece = QLatin1String(pieces[qrand() % piecesCount]);
|
QString piece = QLatin1String(pieces[QRandomGenerator::global()->bounded(piecesCount)]);
|
||||||
if (i == 0 || qrand() % 2) {
|
if (i == 0 || QRandomGenerator::global()->bounded(2)) {
|
||||||
// Make this piece the beginning of a new sentence.
|
// Make this piece the beginning of a new sentence.
|
||||||
piece[0] = piece[0].toUpper();
|
piece[0] = piece[0].toUpper();
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
@ -160,7 +161,7 @@ public:
|
|||||||
for (int i = 0; i < systemsPerPaint; i++) {
|
for (int i = 0; i < systemsPerPaint; i++) {
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
text.append(QLatin1Char(' '));
|
text.append(QLatin1Char(' '));
|
||||||
text.append(samples.at(qrand() % samples.count()));
|
text.append(samples.at(QRandomGenerator::global()->bounded(samples.count())));
|
||||||
}
|
}
|
||||||
p.drawText(QRectF(QPointF(0, 0), QSizeF(size)),
|
p.drawText(QRectF(QPointF(0, 0), QSizeF(size)),
|
||||||
Qt::AlignTop | Qt::AlignAbsolute | Qt::TextWordWrap, text);
|
Qt::AlignTop | Qt::AlignAbsolute | Qt::TextWordWrap, text);
|
||||||
|
@ -29,16 +29,12 @@
|
|||||||
#include "controllerwidget.h"
|
#include "controllerwidget.h"
|
||||||
#include <controls.h>
|
#include <controls.h>
|
||||||
|
|
||||||
#if QT_VERSION >= 0x050000
|
#include <QtWidgets>
|
||||||
# include <QtWidgets>
|
#include <QWindow>
|
||||||
# include <QWindow>
|
#include <QBackingStore>
|
||||||
# include <QBackingStore>
|
#include <QPaintDevice>
|
||||||
# include <QPaintDevice>
|
#include <QPainter>
|
||||||
# include <QPainter>
|
#include <QRandomGenerator>
|
||||||
#else
|
|
||||||
# include <QtGui>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
|
|
||||||
CoordinateControl::CoordinateControl(const QString &sep) : m_x(new QSpinBox), m_y(new QSpinBox)
|
CoordinateControl::CoordinateControl(const QString &sep) : m_x(new QSpinBox), m_y(new QSpinBox)
|
||||||
@ -280,7 +276,7 @@ public:
|
|||||||
explicit Window(QWindow *parent = 0)
|
explicit Window(QWindow *parent = 0)
|
||||||
: QWindow(parent)
|
: QWindow(parent)
|
||||||
, m_backingStore(new QBackingStore(this))
|
, m_backingStore(new QBackingStore(this))
|
||||||
, m_color(Qt::GlobalColor(qrand() % 18))
|
, m_color(Qt::GlobalColor(QRandomGenerator::global()->bounded(18)))
|
||||||
{
|
{
|
||||||
setObjectName(QStringLiteral("window"));
|
setObjectName(QStringLiteral("window"));
|
||||||
setTitle(tr("TestWindow"));
|
setTitle(tr("TestWindow"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user