summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-06-12 16:03:04 -0700
committerLars Knoll <lars.knoll@qt.io>2017-07-04 11:45:30 +0000
commit096b9122b939de19836b75718156cc8155e84621 (patch)
tree248d30bd541891db42b5a70e775f561821c8d571
parentaf03eef4ab3cc41a6148d1f73fef1193f4fc4dcb (diff)
Use QRandomGenerator instead of q?rand
Change-Id: Icd0e0d4b27cb4e5eb892fffd14b5285d43f4afbf Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--examples/datavisualization/draggableaxes/data.cpp10
-rw-r--r--examples/datavisualization/itemmodel/main.cpp4
-rw-r--r--examples/datavisualization/qmloscilloscope/datasource.cpp3
-rw-r--r--examples/datavisualization/scatter/scatterdatamodifier.cpp10
-rw-r--r--tests/manual/barstest/chart.cpp34
-rw-r--r--tests/manual/galaxy/galaxydata.cpp18
-rw-r--r--tests/manual/itemmodeltest/main.cpp5
-rw-r--r--tests/manual/qmlperf/datagenerator.cpp15
-rw-r--r--tests/manual/scattertest/scatterchart.cpp25
-rw-r--r--tests/manual/surfacetest/graphmodifier.cpp41
10 files changed, 91 insertions, 74 deletions
diff --git a/examples/datavisualization/draggableaxes/data.cpp b/examples/datavisualization/draggableaxes/data.cpp
index c2907c4d..67777cdc 100644
--- a/examples/datavisualization/draggableaxes/data.cpp
+++ b/examples/datavisualization/draggableaxes/data.cpp
@@ -29,6 +29,7 @@
#include "data.h"
+#include <QtCore/QRandomGenerator>
#include <QtDataVisualization/QScatterDataProxy>
#include <QtDataVisualization/Q3DScene>
#include <QtDataVisualization/Q3DCamera>
@@ -165,7 +166,10 @@ void Data::addData()
QVector3D Data::randVector()
{
return QVector3D(
- (float)(rand() % 100) / 2.0f - (float)(rand() % 100) / 2.0f,
- (float)(rand() % 100) / 2.0f - (float)(rand() % 100) / 2.0f,
- (float)(rand() % 100) / 2.0f - (float)(rand() % 100) / 2.0f);
+ (float)(QRandomGenerator::bounded(100)) / 2.0f -
+ (float)(QRandomGenerator::bounded(100)) / 2.0f,
+ (float)(QRandomGenerator::bounded(100)) / 2.0f -
+ (float)(QRandomGenerator::bounded(100)) / 2.0f,
+ (float)(QRandomGenerator::bounded(100)) / 2.0f -
+ (float)(QRandomGenerator::bounded(100)) / 2.0f);
}
diff --git a/examples/datavisualization/itemmodel/main.cpp b/examples/datavisualization/itemmodel/main.cpp
index f2197785..f8564578 100644
--- a/examples/datavisualization/itemmodel/main.cpp
+++ b/examples/datavisualization/itemmodel/main.cpp
@@ -40,6 +40,7 @@
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QTableWidget>
#include <QtGui/QScreen>
+#include <QtCore/QRandomGenerator>
#include <QtCore/QTimer>
#include <QtGui/QFont>
#include <QtCore/QDebug>
@@ -216,7 +217,8 @@ void GraphDataGenerator::addRow()
for (int i = 0; i < m_columnCount; i++) {
QModelIndex index = m_tableWidget->model()->index(0, i);
m_tableWidget->model()->setData(index,
- ((float)i / (float)m_columnCount) / 2.0f + (float)(rand() % 30) / 100.0f);
+ ((float)i / (float)m_columnCount) / 2.0f +
+ (float)(QRandomGenerator::bounded(30)) / 100.0f);
}
m_tableWidget->resizeColumnsToContents();
}
diff --git a/examples/datavisualization/qmloscilloscope/datasource.cpp b/examples/datavisualization/qmloscilloscope/datasource.cpp
index 4a9aaddb..cb82c672 100644
--- a/examples/datavisualization/qmloscilloscope/datasource.cpp
+++ b/examples/datavisualization/qmloscilloscope/datasource.cpp
@@ -29,6 +29,7 @@
#include "datasource.h"
#include <QtCore/qmath.h>
+#include <QtCore/qrandom.h>
using namespace QtDataVisualization;
@@ -95,7 +96,7 @@ void DataSource::generateData(int cacheCount, int rowCount, int columnCount,
float colWave = float(qSin((2.0 * M_PI * colMod) - (1.0 / 2.0 * M_PI)) + 1.0);
float y = (colWave * ((float(qSin(rowColWaveAngleMul * colMod) + 1.0))))
* rowColWaveMul
- + (0.15f * float(qrand()) / float(RAND_MAX)) * yRangeMod;
+ + QRandomGenerator::bounded(0.15f) * yRangeMod;
int index = k + cacheIndexAdjustment;
if (index >= columnCount) {
diff --git a/examples/datavisualization/scatter/scatterdatamodifier.cpp b/examples/datavisualization/scatter/scatterdatamodifier.cpp
index efb859a9..025a6fa5 100644
--- a/examples/datavisualization/scatter/scatterdatamodifier.cpp
+++ b/examples/datavisualization/scatter/scatterdatamodifier.cpp
@@ -35,6 +35,7 @@
#include <QtDataVisualization/qscatter3dseries.h>
#include <QtDataVisualization/q3dtheme.h>
#include <QtCore/qmath.h>
+#include <QtCore/qrandom.h>
#include <QtWidgets/QComboBox>
using namespace QtDataVisualization;
@@ -208,7 +209,10 @@ void ScatterDataModifier::toggleItemCount()
QVector3D ScatterDataModifier::randVector()
{
return QVector3D(
- (float)(rand() % 100) / 2.0f - (float)(rand() % 100) / 2.0f,
- (float)(rand() % 100) / 100.0f - (float)(rand() % 100) / 100.0f,
- (float)(rand() % 100) / 2.0f - (float)(rand() % 100) / 2.0f);
+ (float)(QRandomGenerator::bounded(100)) / 2.0f -
+ (float)(QRandomGenerator::bounded(100)) / 2.0f,
+ (float)(QRandomGenerator::bounded(100)) / 100.0f -
+ (float)(QRandomGenerator::bounded(100)) / 100.0f,
+ (float)(QRandomGenerator::bounded(100)) / 2.0f -
+ (float)(QRandomGenerator::bounded(100)) / 2.0f);
}
diff --git a/tests/manual/barstest/chart.cpp b/tests/manual/barstest/chart.cpp
index 4aee80cf..21ef5eaa 100644
--- a/tests/manual/barstest/chart.cpp
+++ b/tests/manual/barstest/chart.cpp
@@ -38,6 +38,7 @@
#include <QtDataVisualization/q3dtheme.h>
#include <QtDataVisualization/q3dinputhandler.h>
#include <QtDataVisualization/qcustom3ditem.h>
+#include <QtCore/QRandomGenerator>
#include <QtCore/QTime>
#include <QtCore/qmath.h>
@@ -378,10 +379,11 @@ void GraphModifier::createMassiveArray()
QBarDataRow *dataRow = new QBarDataRow(arrayDimension);
for (int j = 0; j < arrayDimension; j++) {
if (!m_negativeValuesOn)
- (*dataRow)[j].setValue((float(i % 300 + 1) / 300.0) * float(rand() % int(m_maxval)));
+ (*dataRow)[j].setValue((float(i % 300 + 1) / 300.0)
+ * QRandomGenerator::bounded(m_maxval));
else
- (*dataRow)[j].setValue((float(i % 300 + 1) / 300.0) * float(rand() % int(m_maxval))
- + m_minval);
+ (*dataRow)[j].setValue((float(i % 300 + 1) / 300.0)
+ * QRandomGenerator::bounded(m_maxval) + m_minval);
}
dataArray->append(dataRow);
}
@@ -449,10 +451,12 @@ void GraphModifier::addRow()
QBarDataRow *dataRow = new QBarDataRow(m_columnCount);
for (float i = 0; i < m_columnCount; i++) {
if (!m_negativeValuesOn)
- (*dataRow)[i].setValue(((i + 1) / (float)m_columnCount) * (float)(rand() % int(m_maxval)));
+ (*dataRow)[i].setValue(((i + 1) / (float)m_columnCount)
+ * QRandomGenerator::bounded(m_maxval));
else
- (*dataRow)[i].setValue(((i + 1) / (float)m_columnCount) * (float)(rand() % int(m_maxval))
- - (float)(rand() % int(m_minval)));
+ (*dataRow)[i].setValue(((i + 1) / (float)m_columnCount)
+ * QRandomGenerator::bounded(m_maxval)
+ - QRandomGenerator::bounded(m_minval));
}
// TODO Needs to be changed to account for data window offset once it is implemented.
@@ -480,8 +484,8 @@ void GraphModifier::insertRow()
{
QBarDataRow *dataRow = new QBarDataRow(m_columnCount);
for (float i = 0; i < m_columnCount; i++)
- (*dataRow)[i].setValue(((i + 1) / (float)m_columnCount) * (float)(rand() % int(m_maxval))
- + m_minval);
+ (*dataRow)[i].setValue(((i + 1) / (float)m_columnCount)
+ * QRandomGenerator::bounded(m_maxval) + m_minval);
// TODO Needs to be changed to account for data window offset once it is implemented.
int row = qMax(m_selectedBar.x(), 0);
@@ -515,7 +519,7 @@ void GraphModifier::changeItem()
int row = m_selectedBar.x();
int column = m_selectedBar.y();
if (row >= 0 && column >= 0) {
- QBarDataItem item(float(rand() % 100));
+ QBarDataItem item(float(QRandomGenerator::bounded(100)));
m_genericData->dataProxy()->setItem(row, column, item);
}
}
@@ -527,7 +531,7 @@ void GraphModifier::changeRow()
if (row >= 0) {
QBarDataRow *newRow = new QBarDataRow(m_genericData->dataProxy()->rowAt(row)->size());
for (int i = 0; i < newRow->size(); i++)
- (*newRow)[i].setValue(float(rand() % int(m_maxval)) + m_minval);
+ (*newRow)[i].setValue(QRandomGenerator::bounded(m_maxval) + m_minval);
QString label = QStringLiteral("Change %1").arg(changeCounter++);
m_genericData->dataProxy()->setRow(row, newRow, label);
}
@@ -544,7 +548,7 @@ void GraphModifier::changeRows()
for (int i = startRow; i <= row; i++ ) {
QBarDataRow *newRow = new QBarDataRow(m_genericData->dataProxy()->rowAt(i)->size());
for (int j = 0; j < newRow->size(); j++)
- (*newRow)[j].setValue(float(rand() % int(m_maxval)) + m_minval);
+ (*newRow)[j].setValue(QRandomGenerator::bounded(m_maxval) + m_minval);
newArray.append(newRow);
labels.append(QStringLiteral("Change %1").arg(changeCounter++));
}
@@ -1453,7 +1457,7 @@ void GraphModifier::insertRemoveTimerTimeout()
for (int k = 0; k < 1; k++) {
QBarDataRow *dataRow = new QBarDataRow(10);
for (float i = 0; i < 10; i++)
- (*dataRow)[i].setValue(((i + 1) / 10.0f) * (float)(rand() % 100));
+ (*dataRow)[i].setValue(((i + 1) / 10.0f) * (float)(QRandomGenerator::bounded(100)));
QString label = QStringLiteral("Insert %1").arg(insertCounter++);
m_dummyData->dataProxy()->insertRow(0, dataRow, label);
@@ -1467,7 +1471,7 @@ void GraphModifier::insertRemoveTimerTimeout()
for (int k = 0; k < 2; k++) {
QBarDataRow *dataRow = new QBarDataRow(10);
for (float i = 0; i < 10; i++)
- (*dataRow)[i].setValue(((i + 1) / 10.0f) * (float)(rand() % 100));
+ (*dataRow)[i].setValue(((i + 1) / 10.0f) * (float)(QRandomGenerator::bounded(100)));
QString label = QStringLiteral("Insert %1").arg(insertCounter++);
m_dummyData2->dataProxy()->insertRow(0, dataRow, label);
@@ -1770,7 +1774,7 @@ void GraphModifier::toggleCustomItem()
item->setMeshFile(":/shuttle.obj");
item->setPosition(positionOne);
item->setScaling(QVector3D(0.1f, 0.1f, 0.1f));
- item->setRotation(QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, rand()));
+ item->setRotation(QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, QRandomGenerator::get32()));
item->setTextureImage(QImage(":/shuttle.png"));
m_graph->addCustomItem(item);
} else {
@@ -1779,7 +1783,7 @@ void GraphModifier::toggleCustomItem()
item->setMeshFile(":/shuttle.obj");
item->setPosition(positionTwo);
item->setScaling(QVector3D(0.1f, 0.1f, 0.1f));
- item->setRotation(QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, rand()));
+ item->setRotation(QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, QRandomGenerator::get32()));
item->setTextureImage(QImage(":/shuttle.png"));
m_graph->addCustomItem(item);
}
diff --git a/tests/manual/galaxy/galaxydata.cpp b/tests/manual/galaxy/galaxydata.cpp
index 8a409132..dfd8db94 100644
--- a/tests/manual/galaxy/galaxydata.cpp
+++ b/tests/manual/galaxy/galaxydata.cpp
@@ -44,6 +44,7 @@
#include <QtDataVisualization/qscatter3dseries.h>
#include <QtDataVisualization/q3dtheme.h>
#include <QtCore/qmath.h>
+#include <QtCore/qrandom.h>
#include <QPainter>
#include <QDebug>
@@ -53,7 +54,6 @@ using namespace QtDataVisualization;
static const int numOfStars = 70000;
static const int numOfDust = numOfStars / 2;
static const int numOfH2 = 200;
-static const qreal rand_max = qreal(RAND_MAX);
GalaxyData::GalaxyData(Q3DScatter *scatter,
qreal rad,
@@ -163,12 +163,12 @@ void GalaxyData::createGalaxy()
1000.0); // Anzahl der st├╝tzstellen
for (int i = 3; i < numOfStars; ++i) {
- qreal rad = cd.valFromProp(qreal(qrand()) / rand_max);
+ qreal rad = cd.valFromProp(QRandomGenerator::getReal());
m_pStars[i].m_a = rad;
m_pStars[i].m_b = rad * getExcentricity(rad);
m_pStars[i].m_angle = getAngularOffset(rad);
- m_pStars[i].m_theta = 360.0 * ((double)rand() / RAND_MAX);
+ m_pStars[i].m_theta = 360.0 * QRandomGenerator::getReal();
m_pStars[i].m_center = QVector2D(0.0f, 0.0f);
m_pStars[i].calcXY();
@@ -179,14 +179,14 @@ void GalaxyData::createGalaxy()
qreal x, y, rad;
for (int i = 0; i < numOfDust; ++i)
{
- x = 2.0 * m_radGalaxy * ((double)rand() / RAND_MAX) - m_radGalaxy;
- y = 2.0 * m_radGalaxy * ((double)rand() / RAND_MAX) - m_radGalaxy;
+ x = 2.0 * m_radGalaxy * QRandomGenerator::getReal() - m_radGalaxy;
+ y = 2.0 * m_radGalaxy * QRandomGenerator::getReal() - m_radGalaxy;
rad = sqrt(x*x + y*y);
m_pDust[i].m_a = rad;
m_pDust[i].m_b = rad * getExcentricity(rad);
m_pDust[i].m_angle = getAngularOffset(rad);
- m_pDust[i].m_theta = 360.0 * ((double)rand() / RAND_MAX);
+ m_pDust[i].m_theta = 360.0 * QRandomGenerator::getReal();
m_pDust[i].m_center = QVector2D(0.0f, 0.0f);
m_pDust[i].calcXY();
@@ -196,15 +196,15 @@ void GalaxyData::createGalaxy()
// Initialize H2
for (int i = 0; i < numOfH2; ++i)
{
- x = 2*(m_radGalaxy) * ((double)rand() / RAND_MAX) - (m_radGalaxy);
- y = 2*(m_radGalaxy) * ((double)rand() / RAND_MAX) - (m_radGalaxy);
+ x = 2*(m_radGalaxy) * QRandomGenerator::getReal() - (m_radGalaxy);
+ y = 2*(m_radGalaxy) * QRandomGenerator::getReal() - (m_radGalaxy);
rad = sqrt(x*x + y*y);
int k1 = 2*i;
m_pH2[k1].m_a = rad;
m_pH2[k1].m_b = rad * getExcentricity(rad);
m_pH2[k1].m_angle = getAngularOffset(rad);
- m_pH2[k1].m_theta = 360.0 * ((double)rand() / RAND_MAX);
+ m_pH2[k1].m_theta = 360.0 * QRandomGenerator::getReal();
m_pH2[k1].m_center = QVector2D(0.0f, 0.0f);
m_pH2[k1].calcXY();
diff --git a/tests/manual/itemmodeltest/main.cpp b/tests/manual/itemmodeltest/main.cpp
index 63aa2036..9ccf6ede 100644
--- a/tests/manual/itemmodeltest/main.cpp
+++ b/tests/manual/itemmodeltest/main.cpp
@@ -43,6 +43,7 @@
#include <QtWidgets/QTableWidget>
#include <QtGui/QScreen>
#include <QtCore/QTimer>
+#include <QtCore/QRandomGenerator>
#include <QtCore/QDebug>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QPushButton>
@@ -201,7 +202,7 @@ void GraphDataGenerator::addRow()
QModelIndex index = m_tableWidget->model()->index(0, i);
m_tableWidget->model()->setData(index,
((float)i / (float)m_columnCount) / 2.0f
- + (float)(rand() % 30) / 100.0f);
+ + QRandomGenerator::bounded(30.0 / 100.0f));
}
m_tableWidget->resizeColumnsToContents();
}
@@ -234,7 +235,7 @@ void GraphDataGenerator::fixTableSize()
void GraphDataGenerator::changeSelectedButtonClicked()
{
// Change all selected cells to a random value 1-10
- QVariant value = QVariant::fromValue(float((rand() % 10) + 1));
+ QVariant value = QVariant::fromValue(QRandomGenerator::bounded(10.0) + 1);
QList<QTableWidgetItem *> selectedItems = m_tableWidget->selectedItems();
foreach (QTableWidgetItem *item, selectedItems) {
QString oldData = item->data(Qt::DisplayRole).toString();
diff --git a/tests/manual/qmlperf/datagenerator.cpp b/tests/manual/qmlperf/datagenerator.cpp
index cb5767d3..ec1b7ced 100644
--- a/tests/manual/qmlperf/datagenerator.cpp
+++ b/tests/manual/qmlperf/datagenerator.cpp
@@ -29,6 +29,7 @@
#include "datagenerator.h"
#include <QDebug>
+#include <QRandomGenerator>
using namespace QtDataVisualization;
@@ -58,11 +59,10 @@ void DataGenerator::generateData(QScatter3DSeries *series, uint count)
dataArray->resize(count);
QScatterDataItem *ptrToDataArray = &dataArray->first();
- float rand_max = float(RAND_MAX);
for (uint i = 0; i < count; i++) {
- ptrToDataArray->setPosition(QVector3D(float(qrand()) / rand_max,
- float(qrand()) / rand_max,
- float(qrand()) / rand_max));
+ ptrToDataArray->setPosition(QVector3D(QRandomGenerator::getReal(),
+ QRandomGenerator::getReal(),
+ QRandomGenerator::getReal()));
ptrToDataArray++;
}
@@ -74,11 +74,10 @@ void DataGenerator::add(QScatter3DSeries *series, uint count)
QScatterDataArray appendArray;
appendArray.resize(count);
- float rand_max = float(RAND_MAX);
for (uint i = 0; i < count; i++) {
- appendArray[i].setPosition(QVector3D(float(qrand()) / rand_max,
- float(qrand()) / rand_max,
- float(qrand()) / rand_max));
+ appendArray[i].setPosition(QVector3D(QRandomGenerator::getReal(),
+ QRandomGenerator::getReal(),
+ QRandomGenerator::getReal()));
}
series->dataProxy()->addItems(appendArray);
diff --git a/tests/manual/scattertest/scatterchart.cpp b/tests/manual/scattertest/scatterchart.cpp
index 3bc7aff4..e2f33309 100644
--- a/tests/manual/scattertest/scatterchart.cpp
+++ b/tests/manual/scattertest/scatterchart.cpp
@@ -36,6 +36,7 @@
#include <QtDataVisualization/q3dtheme.h>
#include <QtDataVisualization/Q3DInputHandler>
#include <qmath.h>
+#include <qrandom.h>
using namespace QtDataVisualization;
//#define RANDOM_SCATTER
@@ -119,7 +120,7 @@ void ScatterDataModifier::massiveDataTest()
m_massiveTestCacheArray.resize(cacheSize);
int totalIndex = 0;
for (int i = 0; i < unitCount && totalIndex < cacheSize; i++) {
- unitBase += direction * (float(rand() % 3) / 100.0f);
+ unitBase += direction * (QRandomGenerator::bounded(3) / 100.0f);
if (unitBase > maxY) {
unitBase = maxY;
direction = -1.0f;
@@ -128,9 +129,9 @@ void ScatterDataModifier::massiveDataTest()
direction = 1.0f;
}
for (int j = 0; j < itemsPerUnit && totalIndex < cacheSize; j++) {
- float randFactor = float(rand() % 100) / (100 / yRangeMargin);
+ float randFactor = float(QRandomGenerator::bounded(100)) / (100 / yRangeMargin);
m_massiveTestCacheArray[totalIndex].setPosition(
- QVector3D(float(qrand() % itemsPerUnit),
+ QVector3D(float(QRandomGenerator::bounded(itemsPerUnit)),
unitBase + randFactor, 0.0f));
// Z value is irrelevant, we replace it anyway when we take item to use
totalIndex++;
@@ -780,8 +781,8 @@ void ScatterDataModifier::removeBunch()
void ScatterDataModifier::timeout()
{
- int doWhat = rand() % 10;
- if (!(rand() % 100))
+ int doWhat = QRandomGenerator::bounded(10);
+ if (!(QRandomGenerator::bounded(100)))
doWhat = -1;
switch (doWhat) {
@@ -814,7 +815,7 @@ void ScatterDataModifier::timeout()
break;
case 9:
if (m_chart->seriesList().size())
- m_targetSeries = m_chart->seriesList().at(rand() % m_chart->seriesList().size());
+ m_targetSeries = m_chart->seriesList().at(QRandomGenerator::bounded(m_chart->seriesList().size()));
else
addSeries();
break;
@@ -937,7 +938,7 @@ void ScatterDataModifier::toggleSeriesVisibility()
void ScatterDataModifier::changeSeriesName()
{
if (m_targetSeries)
- m_targetSeries->setName(m_targetSeries->name().append("-").append(QString::number(qrand() % 10)));
+ m_targetSeries->setName(m_targetSeries->name().append("-").append(QString::number(QRandomGenerator::bounded(10))));
}
void ScatterDataModifier::handleAxisXChanged(QValue3DAxis *axis)
@@ -1119,9 +1120,9 @@ void ScatterDataModifier::setHorizontalAspectRatio(int ratio)
QVector3D ScatterDataModifier::randVector()
{
QVector3D retvec = QVector3D(
- (float)(rand() % 100) / 2.0f - (float)(rand() % 100) / 2.0f,
- (float)(rand() % 100) / 100.0f - (float)(rand() % 100) / 100.0f,
- (float)(rand() % 100) / 2.0f - (float)(rand() % 100) / 2.0f);
+ (float)(QRandomGenerator::bounded(100)) / 2.0f - (float)(QRandomGenerator::bounded(100)) / 2.0f,
+ (float)(QRandomGenerator::bounded(100)) / 100.0f - (float)(QRandomGenerator::bounded(100)) / 100.0f,
+ (float)(QRandomGenerator::bounded(100)) / 2.0f - (float)(QRandomGenerator::bounded(100)) / 2.0f);
qDebug() << __FUNCTION__ << retvec;
@@ -1142,8 +1143,8 @@ QScatter3DSeries *ScatterDataModifier::createAndAddSeries()
series->setItemLabelFormat(QStringLiteral("@seriesName: (X:@xLabel / Z:@zLabel) Y:@yLabel"));
series->setMesh(QAbstract3DSeries::MeshSphere);
series->setMeshSmooth(true);
- series->setBaseColor(QColor(rand() % 256, rand() % 256, rand() % 256));
- series->setItemSize(float(rand() % 90 + 10) / 100.0f);
+ series->setBaseColor(QColor(QRandomGenerator::bounded(256), QRandomGenerator::bounded(256), QRandomGenerator::bounded(256)));
+ series->setItemSize(float(QRandomGenerator::bounded(90) + 10) / 100.0f);
QObject::connect(series, &QScatter3DSeries::selectedItemChanged, this,
&ScatterDataModifier::handleSelectionChange);
diff --git a/tests/manual/surfacetest/graphmodifier.cpp b/tests/manual/surfacetest/graphmodifier.cpp
index 42407ddd..59ddfae8 100644
--- a/tests/manual/surfacetest/graphmodifier.cpp
+++ b/tests/manual/surfacetest/graphmodifier.cpp
@@ -35,6 +35,7 @@
#include <QtDataVisualization/Q3DInputHandler>
#include <qmath.h>
+#include <qrandom.h>
#include <QLinearGradient>
#include <QDebug>
#include <QComboBox>
@@ -668,8 +669,8 @@ void GraphModifier::changeStyle()
void GraphModifier::selectButtonClicked()
{
QSurfaceDataProxy *proxy = m_theSeries->dataProxy();
- int row = rand() % proxy->rowCount();
- int col = rand() % proxy->columnCount();
+ int row = QRandomGenerator::bounded(proxy->rowCount());
+ int col = QRandomGenerator::bounded(proxy->columnCount());
m_theSeries->setSelectedPoint(QPoint(row, col));
}
@@ -700,11 +701,11 @@ void GraphModifier::timeout()
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
(*m_planeArray->at(i))[j].setX(m_planeArray->at(i)->at(j).x()
- * ((float((rand() % 10) + 5.0f) / 10000.0f) + 0.999f));
+ * ((float((QRandomGenerator::bounded(10)) + 5.0f) / 10000.0f) + 0.999f));
(*m_planeArray->at(i))[j].setY(m_planeArray->at(i)->at(j).y()
- * ((float((rand() % 10) + 5.0f) / 1000.0f) + 0.99f) + 0.0001f);
+ * ((float((QRandomGenerator::bounded(10)) + 5.0f) / 1000.0f) + 0.99f) + 0.0001f);
(*m_planeArray->at(i))[j].setZ(m_planeArray->at(i)->at(j).z()
- * ((float((rand() % 10) + 5.0f) / 10000.0f) + 0.999f));
+ * ((float((QRandomGenerator::bounded(10)) + 5.0f) / 10000.0f) + 0.999f));
}
}
@@ -893,7 +894,7 @@ void GraphModifier::changeRow()
float maxZ = 10.0f;
float stepX = (maxX - minX) / float(m_xCount - 1);
float stepZ = (maxZ - minZ) / float(m_zCount - 1);
- float i = float(rand() % m_zCount);
+ float i = float(QRandomGenerator::bounded(m_zCount));
QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount);
float z = qMin(maxZ, (i * stepZ + minZ));
@@ -910,7 +911,7 @@ void GraphModifier::changeRow()
static int changeRowSeries = 0;
qDebug() << "Generating new values to a row at random pos for series " << changeRowSeries;
- int row = rand() % m_zCount;
+ int row = QRandomGenerator::bounded(m_zCount);
QSurfaceDataRow *newRow = createMultiRow(row, changeRowSeries, true);
if (m_ascendingZ)
m_multiseries[changeRowSeries]->dataProxy()->setRow(row, newRow);
@@ -984,7 +985,7 @@ void GraphModifier::changeRows()
float maxZ = 10.0f;
float stepX = (maxX - minX) / float(m_xCount - 1);
float stepZ = (maxZ - minZ) / float(m_zCount - 1);
- float start = float(rand() % (m_zCount - 3));
+ float start = float(QRandomGenerator::bounded(m_zCount - 3));
QSurfaceDataArray dataArray;
@@ -1006,7 +1007,7 @@ void GraphModifier::changeRows()
static int changeRowSeries = 0;
qDebug() << "Generating new values for 3 rows at random pos for series " << changeRowSeries;
- int row = rand() % (m_zCount - 3);
+ int row = QRandomGenerator::bounded(m_zCount - 3);
QSurfaceDataArray dataArray;
for (int i = 0; i < 3; i++) {
QSurfaceDataRow *newRow = createMultiRow(row + i, changeRowSeries, true);
@@ -1033,8 +1034,8 @@ void GraphModifier::changeItem()
float maxZ = 10.0f;
float stepX = (maxX - minX) / float(m_xCount - 1);
float stepZ = (maxZ - minZ) / float(m_zCount - 1);
- float i = float(rand() % m_zCount);
- float j = float(rand() % m_xCount);
+ float i = float(QRandomGenerator::bounded(m_zCount));
+ float j = float(QRandomGenerator::bounded(m_xCount));
float x = qMin(maxX, (j * stepX + minX));
float z = qMin(maxZ, (i * stepZ + minZ));
@@ -1047,8 +1048,8 @@ void GraphModifier::changeItem()
#ifdef MULTI_SERIES
static int changeItemSeries = 0;
int full = m_limitX * m_limitZ;
- float i = float(rand() % m_zCount);
- float j = float(rand() % m_xCount);
+ float i = float(QRandomGenerator::bounded(m_zCount));
+ float j = float(QRandomGenerator::bounded(m_xCount));
float x = float(j) - m_limitX + 0.5f + m_multiSampleOffsetX[changeItemSeries];
float z = float(i) - m_limitZ + 0.5f + m_multiSampleOffsetZ[changeItemSeries];
float angle = (z * x) / float(full) * 1.57f;
@@ -1290,10 +1291,10 @@ void GraphModifier::removeRow()
if (m_zCount < 1)
return;
- int row = rand() % m_zCount;
+ int row = QRandomGenerator::bounded(m_zCount);
#ifdef MULTI_SERIES
- int series = rand() % 4;
+ int series = QRandomGenerator::bounded(4);
m_multiseries[series]->dataProxy()->removeRows(row, 1);
#else
m_theSeries->dataProxy()->removeRows(row, 1);
@@ -1306,7 +1307,7 @@ void GraphModifier::resetArray()
qDebug() << "Reset series data array";
int rows = 10;
int columns = 10;
- float randFactor = float(rand() % 100) / 100.0f;
+ float randFactor = float(QRandomGenerator::bounded(100)) / 100.0f;
QSurfaceDataArray *planeArray = new QSurfaceDataArray;
planeArray->reserve(rows);
@@ -1321,7 +1322,7 @@ void GraphModifier::resetArray()
}
#ifdef MULTI_SERIES
- int series = rand() % 4;
+ int series = QRandomGenerator::bounded(4);
m_multiseries[series]->dataProxy()->resetArray(planeArray);
#else
m_theSeries->dataProxy()->resetArray(planeArray);
@@ -1332,7 +1333,7 @@ void GraphModifier::resetArrayEmpty()
{
QSurfaceDataArray *emptyArray = new QSurfaceDataArray;
#ifdef MULTI_SERIES
- int series = rand() % 4;
+ int series = QRandomGenerator::bounded(4);
m_multiseries[series]->dataProxy()->resetArray(emptyArray);
#else
m_theSeries->dataProxy()->resetArray(emptyArray);
@@ -1363,7 +1364,7 @@ void GraphModifier::massiveDataTest()
for (int i = 0; i < cacheSize; i++) {
m_massiveTestCacheArray.append(new QSurfaceDataRow);
m_massiveTestCacheArray[i]->resize(columns);
- rowBase += direction * (float(rand() % 3) / 100.0f);
+ rowBase += direction * (float(QRandomGenerator::bounded(3)) / 100.0f);
if (rowBase > maxY) {
rowBase = maxY;
direction = -1.0f;
@@ -1372,7 +1373,7 @@ void GraphModifier::massiveDataTest()
direction = 1.0f;
}
for (int j = 0; j < columns; j++) {
- float randFactor = float(rand() % 100) / (100 / yRangeMargin);
+ float randFactor = float(QRandomGenerator::bounded(100)) / (100 / yRangeMargin);
(*m_massiveTestCacheArray.at(i))[j].setX(float(j));
(*m_massiveTestCacheArray.at(i))[j].setY(rowBase + randFactor);
// Z value is irrelevant, we replace it anyway when we take row to use