summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-06-12 16:01:04 -0700
committerLars Knoll <lars.knoll@qt.io>2017-07-04 11:46:00 +0000
commitdbb55fba566fd3878b5ef76a2216f0c3f961147f (patch)
tree0c6f4a7a5cfb7dcfa41c88b205ddb155530b228d
parent94f565a00cbc8d779251355cdb94704277711da7 (diff)
Use QRandomGenerator instead of q?rand
Change-Id: Icd0e0d4b27cb4e5eb892fffd14b5285d43f4afbf Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--examples/charts/barmodelmapper/customtablemodel.cpp7
-rw-r--r--examples/charts/chartthemes/themewidget.cpp9
-rw-r--r--examples/charts/datetimeaxis/main.cpp1
-rw-r--r--examples/charts/dynamicspline/chart.cpp6
-rw-r--r--examples/charts/modeldata/customtablemodel.cpp8
-rw-r--r--examples/charts/nesteddonuts/widget.cpp9
-rw-r--r--examples/charts/openglseries/datasource.cpp3
-rw-r--r--examples/charts/piechartdrilldown/main.cpp6
-rw-r--r--examples/charts/qmloscilloscope/datasource.cpp3
-rw-r--r--examples/charts/stackedbarchartdrilldown/main.cpp3
-rw-r--r--examples/charts/zoomlinechart/main.cpp3
-rw-r--r--src/charts/chartthememanager.cpp2
-rw-r--r--tests/auto/qxyseries/tst_qxyseries.cpp8
-rw-r--r--tests/manual/barcharttester/chart-widget.cpp3
-rw-r--r--tests/manual/candlesticktester/mainwidget.cpp7
-rw-r--r--tests/manual/chartviewer/model.h9
-rw-r--r--tests/manual/chartwidgettest/mainwidget.cpp5
-rw-r--r--tests/manual/openglseriestest/datasource.cpp3
-rw-r--r--tests/manual/openglseriestest/mainwindow.cpp3
-rw-r--r--tests/manual/presenterchart/chartview.cpp4
-rw-r--r--tests/manual/wavechart/wavechart.cpp6
21 files changed, 47 insertions, 61 deletions
diff --git a/examples/charts/barmodelmapper/customtablemodel.cpp b/examples/charts/barmodelmapper/customtablemodel.cpp
index 23b5271c..2caef9b5 100644
--- a/examples/charts/barmodelmapper/customtablemodel.cpp
+++ b/examples/charts/barmodelmapper/customtablemodel.cpp
@@ -31,13 +31,12 @@
#include <QtCore/QVector>
#include <QtCore/QTime>
#include <QtCore/QRect>
+#include <QtCore/QRandomGenerator>
#include <QtGui/QColor>
CustomTableModel::CustomTableModel(QObject *parent) :
QAbstractTableModel(parent)
{
- qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
-
m_columnCount = 6;
m_rowCount = 12;
@@ -46,9 +45,9 @@ CustomTableModel::CustomTableModel(QObject *parent) :
QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
for (int k = 0; k < dataVec->size(); k++) {
if (k % 2 == 0)
- dataVec->replace(k, i * 50 + qrand() % 20);
+ dataVec->replace(k, i * 50 + QRandomGenerator::bounded(20));
else
- dataVec->replace(k, qrand() % 100);
+ dataVec->replace(k, QRandomGenerator::bounded(100));
}
m_data.append(dataVec);
}
diff --git a/examples/charts/chartthemes/themewidget.cpp b/examples/charts/chartthemes/themewidget.cpp
index 9739dde1..6f408c75 100644
--- a/examples/charts/chartthemes/themewidget.cpp
+++ b/examples/charts/chartthemes/themewidget.cpp
@@ -49,7 +49,7 @@
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QLabel>
-#include <QtCore/QTime>
+#include <QtCore/QRandomGenerator>
#include <QtCharts/QBarCategoryAxis>
ThemeWidget::ThemeWidget(QWidget *parent) :
@@ -129,16 +129,13 @@ DataTable ThemeWidget::generateRandomData(int listCount, int valueMax, int value
{
DataTable dataTable;
- // set seed for random stuff
- qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
-
// generate random data
for (int i(0); i < listCount; i++) {
DataList dataList;
qreal yValue(0);
for (int j(0); j < valueCount; j++) {
- yValue = yValue + (qreal)(qrand() % valueMax) / (qreal) valueCount;
- QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount),
+ yValue = yValue + QRandomGenerator::bounded(valueMax / (qreal) valueCount);
+ QPointF value((j + QRandomGenerator::getReal()) * ((qreal) m_valueMax / (qreal) valueCount),
yValue);
QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
dataList << Data(value, label);
diff --git a/examples/charts/datetimeaxis/main.cpp b/examples/charts/datetimeaxis/main.cpp
index 9a24a649..ca3f4320 100644
--- a/examples/charts/datetimeaxis/main.cpp
+++ b/examples/charts/datetimeaxis/main.cpp
@@ -43,7 +43,6 @@ QT_CHARTS_USE_NAMESPACE
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
- qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
//![1]
QLineSeries *series = new QLineSeries();
diff --git a/examples/charts/dynamicspline/chart.cpp b/examples/charts/dynamicspline/chart.cpp
index 264f2460..9f33423c 100644
--- a/examples/charts/dynamicspline/chart.cpp
+++ b/examples/charts/dynamicspline/chart.cpp
@@ -31,7 +31,7 @@
#include <QtCharts/QAbstractAxis>
#include <QtCharts/QSplineSeries>
#include <QtCharts/QValueAxis>
-#include <QtCore/QTime>
+#include <QtCore/QRandomGenerator>
#include <QtCore/QDebug>
Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags):
@@ -42,8 +42,6 @@ Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags):
m_x(5),
m_y(1)
{
- qsrand((uint) QTime::currentTime().msec());
-
QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout()));
m_timer.setInterval(1000);
@@ -73,7 +71,7 @@ void Chart::handleTimeout()
qreal x = plotArea().width() / m_axis->tickCount();
qreal y = (m_axis->max() - m_axis->min()) / m_axis->tickCount();
m_x += y;
- m_y = qrand() % 5 - 2.5;
+ m_y = QRandomGenerator::bounded(5) - 2.5;
m_series->append(m_x, m_y);
scroll(x, 0);
if (m_x == 100)
diff --git a/examples/charts/modeldata/customtablemodel.cpp b/examples/charts/modeldata/customtablemodel.cpp
index 1bc607be..98cd8c8c 100644
--- a/examples/charts/modeldata/customtablemodel.cpp
+++ b/examples/charts/modeldata/customtablemodel.cpp
@@ -29,15 +29,13 @@
#include "customtablemodel.h"
#include <QtCore/QVector>
-#include <QtCore/QTime>
+#include <QtCore/QRandomGenerator>
#include <QtCore/QRect>
#include <QtGui/QColor>
CustomTableModel::CustomTableModel(QObject *parent) :
QAbstractTableModel(parent)
{
- qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
-
m_columnCount = 4;
m_rowCount = 15;
@@ -46,9 +44,9 @@ CustomTableModel::CustomTableModel(QObject *parent) :
QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
for (int k = 0; k < dataVec->size(); k++) {
if (k % 2 == 0)
- dataVec->replace(k, i * 50 + qrand() % 20);
+ dataVec->replace(k, i * 50 + QRandomGenerator::bounded(20));
else
- dataVec->replace(k, qrand() % 100);
+ dataVec->replace(k, QRandomGenerator::bounded(100));
}
m_data.append(dataVec);
}
diff --git a/examples/charts/nesteddonuts/widget.cpp b/examples/charts/nesteddonuts/widget.cpp
index 35860a01..533b8969 100644
--- a/examples/charts/nesteddonuts/widget.cpp
+++ b/examples/charts/nesteddonuts/widget.cpp
@@ -32,7 +32,7 @@
#include <QtCharts/QLegend>
#include <QtCharts/QPieSeries>
#include <QtCharts/QPieSlice>
-#include <QtCore/QTime>
+#include <QtCore/QRandomGenerator>
#include <QtWidgets/QGridLayout>
#include <QtCore/QTimer>
@@ -42,7 +42,6 @@ Widget::Widget(QWidget *parent)
: QWidget(parent)
{
setMinimumSize(800, 600);
- qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
//! [1]
QChartView *chartView = new QChartView;
@@ -62,9 +61,9 @@ Widget::Widget(QWidget *parent)
//! [3]
for (int i = 0; i < donutCount; i++) {
QPieSeries *donut = new QPieSeries;
- int sliceCount = 3 + qrand() % 3;
+ int sliceCount = 3 + QRandomGenerator::bounded(3);
for (int j = 0; j < sliceCount; j++) {
- qreal value = 100 + qrand() % 100;
+ qreal value = 100 + QRandomGenerator::bounded(100);
QPieSlice *slice = new QPieSlice(QString("%1").arg(value), value);
slice->setLabelVisible(true);
slice->setLabelColor(Qt::white);
@@ -103,7 +102,7 @@ void Widget::updateRotation()
{
for (int i = 0; i < m_donuts.count(); i++) {
QPieSeries *donut = m_donuts.at(i);
- qreal phaseShift = -50 + qrand() % 100;
+ qreal phaseShift = -50 + QRandomGenerator::bounded(100);
donut->setPieStartAngle(donut->pieStartAngle() + phaseShift);
donut->setPieEndAngle(donut->pieEndAngle() + phaseShift);
}
diff --git a/examples/charts/openglseries/datasource.cpp b/examples/charts/openglseries/datasource.cpp
index 291bc722..1448e54e 100644
--- a/examples/charts/openglseries/datasource.cpp
+++ b/examples/charts/openglseries/datasource.cpp
@@ -29,6 +29,7 @@
#include "datasource.h"
#include <QtCore/QtMath>
+#include <QtCore/QRandomGenerator>
QT_CHARTS_USE_NAMESPACE
@@ -118,7 +119,7 @@ void DataSource::generateData(int seriesCount, int rowCount, int colCount)
qreal y(0);
// data with sin + random component
y = height + (yMultiplier * qSin(M_PI / 50 * j)
- + (yMultiplier * (qreal) rand() / (qreal) RAND_MAX));
+ + (yMultiplier * QRandomGenerator::getReal()));
// 0.000001 added to make values logaxis compatible
x = 0.000001 + 20.0 * (qreal(j) / qreal(colCount)) + (xAdjustment * qreal(i));
points.append(QPointF(x, y));
diff --git a/examples/charts/piechartdrilldown/main.cpp b/examples/charts/piechartdrilldown/main.cpp
index 69f87158..bea7fb3c 100644
--- a/examples/charts/piechartdrilldown/main.cpp
+++ b/examples/charts/piechartdrilldown/main.cpp
@@ -31,7 +31,7 @@
#include "drilldownslice.h"
#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
-#include <QtCore/QTime>
+#include <QtCore/QRandomGenerator>
#include <QtCharts/QChartView>
#include <QtCharts/QLegend>
#include <QtCharts/QPieSeries>
@@ -42,8 +42,6 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
- qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
-
QMainWindow window;
DrilldownChart *chart = new DrilldownChart();
@@ -65,7 +63,7 @@ int main(int argc, char *argv[])
series->setName("Sales by month - " + name);
foreach (QString month, months)
- *series << new DrilldownSlice(qrand() % 1000, month, yearSeries);
+ *series << new DrilldownSlice(QRandomGenerator::bounded(1000), month, yearSeries);
QObject::connect(series, SIGNAL(clicked(QPieSlice*)), chart, SLOT(handleSliceClicked(QPieSlice*)));
diff --git a/examples/charts/qmloscilloscope/datasource.cpp b/examples/charts/qmloscilloscope/datasource.cpp
index f687beb0..1f6c7272 100644
--- a/examples/charts/qmloscilloscope/datasource.cpp
+++ b/examples/charts/qmloscilloscope/datasource.cpp
@@ -33,6 +33,7 @@
#include <QtQuick/QQuickView>
#include <QtQuick/QQuickItem>
#include <QtCore/QDebug>
+#include <QtCore/QRandomGenerator>
#include <QtCore/QtMath>
QT_CHARTS_USE_NAMESPACE
@@ -82,7 +83,7 @@ void DataSource::generateData(int type, int rowCount, int colCount)
switch (type) {
case 0:
// data with sin + random component
- y = qSin(M_PI / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX;
+ y = qSin(M_PI / 50 * j) + 0.5 + QRandomGenerator::getReal();
x = j;
break;
case 1:
diff --git a/examples/charts/stackedbarchartdrilldown/main.cpp b/examples/charts/stackedbarchartdrilldown/main.cpp
index c3e03505..f4bbc3f0 100644
--- a/examples/charts/stackedbarchartdrilldown/main.cpp
+++ b/examples/charts/stackedbarchartdrilldown/main.cpp
@@ -29,6 +29,7 @@
#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
+#include <QtCore/QRandomGenerator>
#include <QtCharts/QChartView>
#include <QtCharts/QBarSet>
#include <QtCharts/QLegend>
@@ -90,7 +91,7 @@ int main(int argc, char *argv[])
for (int month = 0; month < months.count(); month++) {
QBarSet *weeklyCrop = new QBarSet(plant);
for (int week = 0; week < weeks.count(); week++)
- *weeklyCrop << (qrand() % 20);
+ *weeklyCrop << QRandomGenerator::bounded(20);
// Get the drilldown series from season series and add crop to it.
seasonSeries->drilldownSeries(month)->append(weeklyCrop);
*monthlyCrop << weeklyCrop->sum();
diff --git a/examples/charts/zoomlinechart/main.cpp b/examples/charts/zoomlinechart/main.cpp
index 6a80982b..b3c6a33f 100644
--- a/examples/charts/zoomlinechart/main.cpp
+++ b/examples/charts/zoomlinechart/main.cpp
@@ -32,6 +32,7 @@
#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QtCore/QtMath>
+#include <QtCore/QRandomGenerator>
#include <QtCharts/QLineSeries>
#include <QtCharts/QValueAxis>
@@ -45,7 +46,7 @@ int main(int argc, char *argv[])
QLineSeries *series = new QLineSeries();
for (int i = 0; i < 500; i++) {
QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
- p.ry() += qrand() % 20;
+ p.ry() += QRandomGenerator::bounded(20);
*series << p;
}
//![1]
diff --git a/src/charts/chartthememanager.cpp b/src/charts/chartthememanager.cpp
index 2840b132..6d6f6cb7 100644
--- a/src/charts/chartthememanager.cpp
+++ b/src/charts/chartthememanager.cpp
@@ -28,7 +28,6 @@
****************************************************************************/
#include <private/qabstractseries_p.h>
#include <private/qabstractaxis_p.h>
-#include <QtCore/QTime>
//themes
#include <private/chartthemesystem_p.h>
#include <private/chartthemelight_p.h>
@@ -45,7 +44,6 @@ QT_CHARTS_BEGIN_NAMESPACE
ChartThemeManager::ChartThemeManager(QChart* chart) :
m_chart(chart)
{
- qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
}
diff --git a/tests/auto/qxyseries/tst_qxyseries.cpp b/tests/auto/qxyseries/tst_qxyseries.cpp
index 767caca2..f55f5147 100644
--- a/tests/auto/qxyseries/tst_qxyseries.cpp
+++ b/tests/auto/qxyseries/tst_qxyseries.cpp
@@ -325,7 +325,7 @@ void tst_QXYSeries::remove_raw()
// (simulate e.g. spamming a hypothetical "remove last point"-button)
QList<QPointF> bunchOfPoints;
for (int i = 0; i < 10; i++)
- bunchOfPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX));
+ bunchOfPoints.append(QPointF(i, QRandomGenerator::getReal()));
m_series->replace(bunchOfPoints);
QCOMPARE(m_series->points(), bunchOfPoints);
QTest::qWait(1500); // Wait for append animations to be over
@@ -337,7 +337,7 @@ void tst_QXYSeries::remove_raw()
// Removal using index
for (int i = 0; i < 10; i++)
- bunchOfPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX));
+ bunchOfPoints.append(QPointF(i, QRandomGenerator::getReal()));
m_series->replace(bunchOfPoints);
m_series->remove(5);
m_series->remove(0);
@@ -350,7 +350,7 @@ void tst_QXYSeries::remove_raw()
// Multiple removal using index
for (int i = 0; i < 10; i++)
- bunchOfPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX));
+ bunchOfPoints.append(QPointF(i, QRandomGenerator::getReal()));
m_series->replace(bunchOfPoints);
m_series->removePoints(5, 2);
m_series->removePoints(0, 3);
@@ -463,7 +463,7 @@ void tst_QXYSeries::replace_raw()
// Replace all points
QList<QPointF> allPoints;
for (int i = 0; i < 10; i++)
- allPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX));
+ allPoints.append(QPointF(i, QRandomGenerator::getReal()));
m_series->replace(allPoints);
TRY_COMPARE(pointReplacedSpy.count(), points.count());
TRY_COMPARE(pointsReplacedSpy.count(), 1);
diff --git a/tests/manual/barcharttester/chart-widget.cpp b/tests/manual/barcharttester/chart-widget.cpp
index 6e7157b1..3c58f5ce 100644
--- a/tests/manual/barcharttester/chart-widget.cpp
+++ b/tests/manual/barcharttester/chart-widget.cpp
@@ -40,7 +40,6 @@
#include <QtCharts/QHorizontalStackedBarSeries>
#include <QtCharts/QPercentBarSeries>
#include <QtCharts/QStackedBarSeries>
-#include <QtCore/QTime>
#include <QElapsedTimer>
#include <QDebug>
@@ -152,8 +151,6 @@ ChartWidget::ChartWidget(QWidget *parent) :
series->setBarWidth(barWidth);
}
- qsrand((uint) QTime::currentTime().msec());
-
resize(800, 300);
m_horizontalLayout = new QHBoxLayout(this);
m_horizontalLayout->setSpacing(6);
diff --git a/tests/manual/candlesticktester/mainwidget.cpp b/tests/manual/candlesticktester/mainwidget.cpp
index 9c902a3f..f45a7793 100644
--- a/tests/manual/candlesticktester/mainwidget.cpp
+++ b/tests/manual/candlesticktester/mainwidget.cpp
@@ -35,6 +35,7 @@
#include <QtCharts/QValueAxis>
#include <QtCore/QDateTime>
#include <QtCore/QDebug>
+#include <QtCore/QRandomGenerator>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QDoubleSpinBox>
@@ -64,8 +65,6 @@ MainWidget::MainWidget(QWidget *parent)
m_customDecreasingColor(false),
m_hModelMapper(new QHCandlestickModelMapper(this))
{
- qsrand(QDateTime::currentDateTime().toTime_t());
-
m_chartView->setRenderHint(QPainter::Antialiasing, false);
m_hModelMapper->setModel(new CustomTableModel(this));
@@ -285,7 +284,9 @@ QGridLayout *MainWidget::createModelMapperControlsLayout()
qreal MainWidget::randomValue(int min, int max) const
{
- return (qrand() / (qreal(RAND_MAX) + 1)) * ((qMax(min, max) - qMin(min, max)) + qMin(min, max));
+ if (min > max)
+ qSwap(min, max);
+ return QRandomGenerator::bounded(min, max);
}
QCandlestickSet *MainWidget::randomSet(qreal timestamp)
diff --git a/tests/manual/chartviewer/model.h b/tests/manual/chartviewer/model.h
index fcc53724..5db91e8e 100644
--- a/tests/manual/chartviewer/model.h
+++ b/tests/manual/chartviewer/model.h
@@ -33,8 +33,8 @@
#include <QtCore/QList>
#include <QtCore/QPair>
#include <QtCore/QPointF>
+#include <QtCore/QRandomGenerator>
#include <QtCore/QTime>
-#include <stdlib.h>
typedef QPair<QPointF, QString> Data;
typedef QList<Data> DataList;
@@ -51,17 +51,14 @@ public:
{
DataTable dataTable;
- // set seed for random stuff
- qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
-
// generate random data
for (int i(0); i < listCount; i++) {
DataList dataList;
qreal yValue(0.1);
for (int j(0); j < valueCount; j++) {
- yValue = yValue + (qreal)(qrand() % valueMax) / (qreal) valueCount;
+ yValue = yValue + QRandomGenerator::bounded(valueMax / (qreal) valueCount);
QPointF value(
- (j + (qreal) qrand() / (qreal) RAND_MAX)
+ (j + QRandomGenerator::getReal())
* ((qreal) valueMax / (qreal) valueCount), yValue);
QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
dataList << Data(value, label);
diff --git a/tests/manual/chartwidgettest/mainwidget.cpp b/tests/manual/chartwidgettest/mainwidget.cpp
index c471d0bc..2850de0e 100644
--- a/tests/manual/chartwidgettest/mainwidget.cpp
+++ b/tests/manual/chartwidgettest/mainwidget.cpp
@@ -50,6 +50,7 @@
#include <QtWidgets/QMessageBox>
#include <qmath.h>
#include <QtCore/QDebug>
+#include <QtCore/QRandomGenerator>
#include <QtGui/QStandardItemModel>
#include <QtCharts/QBarCategoryAxis>
#include <QtWidgets/QOpenGLWidget>
@@ -218,9 +219,9 @@ QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QStr
if (dataCharacteristics == "Sin") {
newColumn.append(std::abs(sin(M_PI / 50 * i) * 100));
} else if (dataCharacteristics == "Sin + random") {
- newColumn.append(std::abs(sin(M_PI / 50 * i) * 100) + (rand() % 5));
+ newColumn.append(std::abs(sin(M_PI / 50 * i) * 100) + QRandomGenerator::bounded(5));
} else if (dataCharacteristics == "Random") {
- newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
+ newColumn.append(QRandomGenerator::bounded(11.0));
} else if (dataCharacteristics == "Linear") {
//newColumn.append(i * (j + 1.0));
// TODO: temporary hack to make pie work; prevent zero values:
diff --git a/tests/manual/openglseriestest/datasource.cpp b/tests/manual/openglseriestest/datasource.cpp
index 4017676b..29d7e2ba 100644
--- a/tests/manual/openglseriestest/datasource.cpp
+++ b/tests/manual/openglseriestest/datasource.cpp
@@ -29,6 +29,7 @@
#include "datasource.h"
#include <QtCore/QtMath>
+#include <QtCore/QRandomGenerator>
QT_CHARTS_USE_NAMESPACE
@@ -118,7 +119,7 @@ void DataSource::generateData(int seriesIndex, int rowCount, int colCount)
qreal y(0);
// data with sin + random component
y = height + (yMultiplier * qSin(M_PI / 50 * j)
- + (yMultiplier * (qreal) rand() / (qreal) RAND_MAX));
+ + (yMultiplier * QRandomGenerator::getReal()));
// 0.000001 added to make values logaxis compatible
x = 0.000001 + 20.0 * (qreal(j) / qreal(colCount)) + (xAdjustment * qreal(i));
points.append(QPointF(x, y));
diff --git a/tests/manual/openglseriestest/mainwindow.cpp b/tests/manual/openglseriestest/mainwindow.cpp
index 4aaeed13..2d59f18c 100644
--- a/tests/manual/openglseriestest/mainwindow.cpp
+++ b/tests/manual/openglseriestest/mainwindow.cpp
@@ -36,6 +36,7 @@
#include <QtCharts/QDateTimeAxis>
#include <QtCharts/QCategoryAxis>
#include <QtCharts/QChart>
+#include <QtCore/QRandomGenerator>
#include <QtCore/QDebug>
#include <QtCore/QDateTime>
@@ -548,7 +549,7 @@ void MainWindow::addSeries(bool gl)
if (m_seriesList.size() < maxSeriesCount) {
QXYSeries *series;
- if (qrand() % 2) {
+ if (QRandomGenerator::bounded(2)) {
series = new QLineSeries;
series->setPen(QPen(QBrush(color), width));
} else {
diff --git a/tests/manual/presenterchart/chartview.cpp b/tests/manual/presenterchart/chartview.cpp
index 4bbf8080..86d144ad 100644
--- a/tests/manual/presenterchart/chartview.cpp
+++ b/tests/manual/presenterchart/chartview.cpp
@@ -32,7 +32,7 @@
#include <QtCharts/QScatterSeries>
#include <QtCharts/QSplineSeries>
#include <QtCharts/QAreaSeries>
-#include <QtCore/QTime>
+#include <QtCore/QRandomGenerator>
ChartView::ChartView(QChart *chart, QWidget *parent)
: QChartView(chart, parent),
@@ -62,7 +62,7 @@ ChartView::ChartView(QChart *chart, QWidget *parent)
int numPoints = 10;
for (int x = 0; x <= numPoints; ++x) {
- qreal y = qrand() % 100;
+ qreal y = QRandomGenerator::bounded(100);
series0->append(x, y);
series1->append(x, y);
series2->append(x, y);
diff --git a/tests/manual/wavechart/wavechart.cpp b/tests/manual/wavechart/wavechart.cpp
index 72e5e737..522d2a7c 100644
--- a/tests/manual/wavechart/wavechart.cpp
+++ b/tests/manual/wavechart/wavechart.cpp
@@ -29,6 +29,7 @@
#include "wavechart.h"
#include <qmath.h>
+#include <qrandom.h>
QT_CHARTS_USE_NAMESPACE
@@ -46,9 +47,6 @@ WaveChart::WaveChart(QChart* chart, QWidget* parent) :
chart->legend()->setVisible(false);
- QTime now = QTime::currentTime();
- qsrand((uint) now.msec());
-
int fluctuate = 100;
for (qreal x = 0; x <= 2 * M_PI; x += m_step) {
@@ -69,7 +67,7 @@ void WaveChart::update()
int fluctuate;
const QList<QPointF>& points = m_series->points();
for (qreal i = 0, x = 0; x <= 2 * M_PI; x += m_step, i++) {
- fluctuate = qrand() % 100;
+ fluctuate = QRandomGenerator::bounded(100);
m_series->replace(x,points[i].y(),x,fabs(sin(x) * fluctuate));
}