diff options
Diffstat (limited to 'examples/widgets/animation')
6 files changed, 12 insertions, 14 deletions
diff --git a/examples/widgets/animation/animatedtiles/main.cpp b/examples/widgets/animation/animatedtiles/main.cpp index 0511fe8162..89b5b67f8a 100644 --- a/examples/widgets/animation/animatedtiles/main.cpp +++ b/examples/widgets/animation/animatedtiles/main.cpp @@ -50,6 +50,7 @@ #include <QtWidgets> #include <QtCore/qmath.h> +#include <QtCore/qrandom.h> #include <QtCore/qstate.h> class Pixmap : public QObject, public QGraphicsPixmapItem @@ -202,8 +203,8 @@ int main(int argc, char **argv) // Random randomState->assignProperty(item, "pos", - QPointF(-250 + qrand() % 500, - -250 + qrand() % 500)); + QPointF(-250 + QRandomGenerator::global()->bounded(500), + -250 + QRandomGenerator::global()->bounded(500))); // Tiled tiledState->assignProperty(item, "pos", diff --git a/examples/widgets/animation/moveblocks/main.cpp b/examples/widgets/animation/moveblocks/main.cpp index a9b95808a5..6d17696108 100644 --- a/examples/widgets/animation/moveblocks/main.cpp +++ b/examples/widgets/animation/moveblocks/main.cpp @@ -125,7 +125,7 @@ public: void onEntry(QEvent *) override { int n; - while ((n = (qrand() % m_stateCount + 1)) == m_lastIndex) + while ((n = QRandomGenerator::global()->bounded(m_stateCount) + 1) == m_lastIndex) { } m_lastIndex = n; machine()->postEvent(new StateSwitchEvent(n)); @@ -323,8 +323,6 @@ int main(int argc, char **argv) window.resize(300, 300); window.show(); - qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); - return app.exec(); } diff --git a/examples/widgets/animation/stickman/lifecycle.cpp b/examples/widgets/animation/stickman/lifecycle.cpp index 253af22b2d..dbe9a299b4 100644 --- a/examples/widgets/animation/stickman/lifecycle.cpp +++ b/examples/widgets/animation/stickman/lifecycle.cpp @@ -91,13 +91,12 @@ public: : QEventTransition(this, QEvent::Timer) { setTargetState(target); - qsrand((uint)QDateTime::currentSecsSinceEpoch()); startTimer(1000); } bool eventTest(QEvent *e) override { - return QEventTransition::eventTest(e) && ((qrand() % 50) == 0); + return QEventTransition::eventTest(e) && QRandomGenerator::global()->bounded(50) == 0; } }; //! [4] diff --git a/examples/widgets/animation/sub-attaq/main.cpp b/examples/widgets/animation/sub-attaq/main.cpp index f65ca7be18..9b28d8c40f 100644 --- a/examples/widgets/animation/sub-attaq/main.cpp +++ b/examples/widgets/animation/sub-attaq/main.cpp @@ -57,8 +57,6 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); Q_INIT_RESOURCE(subattaq); - qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); - MainWindow w; w.show(); diff --git a/examples/widgets/animation/sub-attaq/states.cpp b/examples/widgets/animation/sub-attaq/states.cpp index 21cff048e7..e19704db7b 100644 --- a/examples/widgets/animation/sub-attaq/states.cpp +++ b/examples/widgets/animation/sub-attaq/states.cpp @@ -64,6 +64,7 @@ #include <QtCore/QStateMachine> #include <QtWidgets/QKeyEventTransition> #include <QtCore/QFinalState> +#include <QtCore/QRandomGenerator> PlayState::PlayState(GraphicsScene *scene, QState *parent) : QState(parent), @@ -193,12 +194,12 @@ void LevelState::initializeLevel() for (int j = 0; j < subContent.second; ++j ) { SubMarine *sub = new SubMarine(submarineDesc.type, submarineDesc.name, submarineDesc.points); 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 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->setCurrentDirection(x == 0 ? SubMarine::Right : SubMarine::Left); - sub->setCurrentSpeed(qrand() % 3 + 1); + sub->setCurrentSpeed(QRandomGenerator::global()->bounded(3) + 1); } } } diff --git a/examples/widgets/animation/sub-attaq/submarine_p.h b/examples/widgets/animation/sub-attaq/submarine_p.h index b8d5532962..698b4b494f 100644 --- a/examples/widgets/animation/sub-attaq/submarine_p.h +++ b/examples/widgets/animation/sub-attaq/submarine_p.h @@ -69,6 +69,7 @@ //Qt #include <QtCore/QPropertyAnimation> +#include <QtCore/QRandomGenerator> #include <QtWidgets/QGraphicsScene> //This state is describing when the boat is moving right @@ -88,8 +89,8 @@ public: protected slots: void onAnimationMovementValueChanged(const QVariant &) { - if (qrand() % 200 + 1 == 3) - submarine->launchTorpedo(qrand() % 3 + 1); + if (QRandomGenerator::global()->bounded(200) + 1 == 3) + submarine->launchTorpedo(QRandomGenerator::global()->bounded(3) + 1); } protected: |