summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2019-03-27 18:59:47 +0000
committerEdward Welbourne <edward.welbourne@qt.io>2019-04-01 14:39:53 +0000
commit4690d4efa64f6b2c23acbebedfa5c8ec75e899ae (patch)
treeeccf62d874f1b3e9ec2e4ddc17fbf99c52b4fb7f /examples
parentf3002b6e205463305502600df95b1ae509e47a9b (diff)
Fix use of qrand/qsrand in an example
Convert an example to use QRandomGenerator::global(). This saves the need for seeding. At the same time, use continuum random values rather than discrete ones, to better fit what the example using it is doing. Change-Id: I0adebaadb2e35832c629e314fda37e60b51f760d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/vulkan/hellovulkancubes/renderer.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/examples/vulkan/hellovulkancubes/renderer.cpp b/examples/vulkan/hellovulkancubes/renderer.cpp
index 5ada79ce79..f104d79002 100644
--- a/examples/vulkan/hellovulkancubes/renderer.cpp
+++ b/examples/vulkan/hellovulkancubes/renderer.cpp
@@ -49,6 +49,7 @@
****************************************************************************/
#include "renderer.h"
+#include "qrandom.h"
#include <QVulkanFunctions>
#include <QtConcurrentRun>
#include <QTime>
@@ -77,8 +78,6 @@ Renderer::Renderer(VulkanWindow *w, int initialCount)
m_cam(QVector3D(0.0f, 0.0f, 20.0f)), // starting camera position
m_instCount(initialCount)
{
- qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
-
m_floorModel.translate(0, -5, 0);
m_floorModel.rotate(-90, 1, 0, 0);
m_floorModel.scale(20, 100, 1);
@@ -793,7 +792,9 @@ void Renderer::ensureInstanceBuffer()
qDebug("Preparing instances %d..%d", m_preparedInstCount, m_instCount - 1);
char *p = m_instData.data();
p += m_preparedInstCount * PER_INSTANCE_DATA_SIZE;
- auto gen = [](float a, float b) { return float((qrand() % int(b - a + 1)) + a); };
+ auto gen = [](int a, int b) {
+ return float(QRandomGenerator::global()->bounded(double(b - a)) + a);
+ };
for (int i = m_preparedInstCount; i < m_instCount; ++i) {
// Apply a random translation to each instance of the mesh.
float t[] = { gen(-5, 5), gen(-4, 6), gen(-30, 5) };