forked from qt-creator/qt-creator
Replace qrand with QRandomGenerator
Task-number: QTCREATORBUG-24098 Change-Id: I91b610409a413c7d76b3c5dd43cf581a960edf7d Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -645,7 +645,7 @@ static QString getUserFilePath(const QString &proposalFileName)
|
|||||||
if (++count > 15)
|
if (++count > 15)
|
||||||
return QString();
|
return QString();
|
||||||
// add random number
|
// add random number
|
||||||
const int number = QRandomGenerator().generate() % 1000;
|
const int number = QRandomGenerator::global()->generate() % 1000;
|
||||||
tryPath = newFilePath + QString::number(number) + suffix;
|
tryPath = newFilePath + QString::number(number) + suffix;
|
||||||
}
|
}
|
||||||
return tryPath;
|
return tryPath;
|
||||||
|
@@ -56,8 +56,9 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <QPlainTextEdit>
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QPlainTextEdit>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
@@ -420,8 +421,10 @@ static void scatterItem(const ModelNode &pastedNode, const ModelNode &targetNode
|
|||||||
double y = pastedNode.variantProperty("y").value().toDouble();
|
double y = pastedNode.variantProperty("y").value().toDouble();
|
||||||
double targetWidth = 20;
|
double targetWidth = 20;
|
||||||
double targetHeight = 20;
|
double targetHeight = 20;
|
||||||
x = x + double(qrand()) / RAND_MAX * targetWidth - targetWidth / 2;
|
x = x + double(QRandomGenerator::global()->generate()) / RAND_MAX * targetWidth
|
||||||
y = y + double(qrand()) / RAND_MAX * targetHeight - targetHeight / 2;
|
- targetWidth / 2;
|
||||||
|
y = y + double(QRandomGenerator::global()->generate()) / RAND_MAX * targetHeight
|
||||||
|
- targetHeight / 2;
|
||||||
pastedNode.variantProperty("x").setValue(int(x));
|
pastedNode.variantProperty("x").setValue(int(x));
|
||||||
pastedNode.variantProperty("y").setValue(int(y));
|
pastedNode.variantProperty("y").setValue(int(y));
|
||||||
} else {
|
} else {
|
||||||
@@ -489,7 +492,7 @@ void DesignDocument::paste()
|
|||||||
rewriterView()->executeInTransaction("DesignDocument::paste1", [&view, selectedNodes, targetNode](){
|
rewriterView()->executeInTransaction("DesignDocument::paste1", [&view, selectedNodes, targetNode](){
|
||||||
QList<ModelNode> pastedNodeList;
|
QList<ModelNode> pastedNodeList;
|
||||||
|
|
||||||
int offset = double(qrand()) / RAND_MAX * 20 - 10;
|
int offset = double(QRandomGenerator::global()->generate()) / RAND_MAX * 20 - 10;
|
||||||
|
|
||||||
foreach (const ModelNode &node, selectedNodes) {
|
foreach (const ModelNode &node, selectedNodes) {
|
||||||
PropertyName defaultProperty(targetNode.metaInfo().defaultPropertyName());
|
PropertyName defaultProperty(targetNode.metaInfo().defaultPropertyName());
|
||||||
|
@@ -37,8 +37,9 @@
|
|||||||
#include "stateitem.h"
|
#include "stateitem.h"
|
||||||
#include "transitionitem.h"
|
#include "transitionitem.h"
|
||||||
|
|
||||||
#include <QGuiApplication>
|
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
#include <QGuiApplication>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
|
|
||||||
namespace ScxmlEditor {
|
namespace ScxmlEditor {
|
||||||
@@ -236,7 +237,7 @@ void layout(const QList<QGraphicsItem*> &items)
|
|||||||
if (finalItem && finalItem->inputTransitionCount() > 0)
|
if (finalItem && finalItem->inputTransitionCount() > 0)
|
||||||
lastItem = finalItem->inputTransitions().constFirst()->connectedItem(finalItem);
|
lastItem = finalItem->inputTransitions().constFirst()->connectedItem(finalItem);
|
||||||
|
|
||||||
int startAngle = qrand() % 2 == 0 ? 180 : 90;
|
int startAngle = QRandomGenerator::global()->generate() % 2 == 0 ? 180 : 90;
|
||||||
int startDistance = 40 + childItems.count() * 10;
|
int startDistance = 40 + childItems.count() * 10;
|
||||||
if (!childItems.isEmpty()) {
|
if (!childItems.isEmpty()) {
|
||||||
// Init position of the items
|
// Init position of the items
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QRandomGenerator>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
namespace Valgrind {
|
namespace Valgrind {
|
||||||
@@ -42,9 +43,10 @@ QColor CallgrindHelper::colorForString(const QString &text)
|
|||||||
return colorCache.value(text);
|
return colorCache.value(text);
|
||||||
|
|
||||||
// Minimum lightness of 100 to be readable with black text.
|
// Minimum lightness of 100 to be readable with black text.
|
||||||
const QColor color = QColor::fromHsl(((qreal)qrand() / RAND_MAX * 359),
|
const QColor color = QColor::fromHsl(
|
||||||
((qreal)qrand() / RAND_MAX * 255),
|
((qreal) QRandomGenerator::global()->generate() / RAND_MAX * 359),
|
||||||
((qreal)qrand() / RAND_MAX * 127) + 128);
|
((qreal) QRandomGenerator::global()->generate() / RAND_MAX * 255),
|
||||||
|
((qreal) QRandomGenerator::global()->generate() / RAND_MAX * 127) + 128);
|
||||||
colorCache[text] = color;
|
colorCache[text] = color;
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
@@ -27,12 +27,12 @@
|
|||||||
#include "outputgenerator.h"
|
#include "outputgenerator.h"
|
||||||
|
|
||||||
#include <QAbstractSocket>
|
#include <QAbstractSocket>
|
||||||
#include <QIODevice>
|
|
||||||
#include <QTextStream>
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QStringList>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QIODevice>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QTextStream>
|
||||||
|
|
||||||
// Yes, this is ugly. But please don't introduce a libUtils dependency
|
// Yes, this is ugly. But please don't introduce a libUtils dependency
|
||||||
// just to get rid of a single function.
|
// just to get rid of a single function.
|
||||||
@@ -123,14 +123,14 @@ void OutputGenerator::produceRuntimeError()
|
|||||||
|
|
||||||
void OutputGenerator::writeOutput()
|
void OutputGenerator::writeOutput()
|
||||||
{
|
{
|
||||||
m_timer.setInterval(qrand() % 1000);
|
m_timer.setInterval(QRandomGenerator::global()->generate() % 1000);
|
||||||
|
|
||||||
int lines = 0;
|
int lines = 0;
|
||||||
while (!m_input->atEnd()) {
|
while (!m_input->atEnd()) {
|
||||||
qint64 lastPos = m_input->pos();
|
qint64 lastPos = m_input->pos();
|
||||||
QByteArray line = m_input->readLine();
|
QByteArray line = m_input->readLine();
|
||||||
if (lines > 0 && !m_finished && line.contains("<error>")) {
|
if (lines > 0 && !m_finished && line.contains("<error>")) {
|
||||||
if ((m_crash || m_garbage || m_wait) && qrand() % 10 == 1) {
|
if ((m_crash || m_garbage || m_wait) && QRandomGenerator::global()->generate() % 10 == 1) {
|
||||||
produceRuntimeError();
|
produceRuntimeError();
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user