QtBase  v6.3.1
src_corelib_global_qrandom.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 Intel Corporation.
4 ** Copyright (C) 2018 The Qt Company Ltd.
5 ** Contact: https://www.qt.io/licensing/
6 **
7 ** This file is part of the documentation of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** BSD License Usage
19 ** Alternatively, you may use this file under the terms of the BSD license
20 ** as follows:
21 **
22 ** "Redistribution and use in source and binary forms, with or without
23 ** modification, are permitted provided that the following conditions are
24 ** met:
25 ** * Redistributions of source code must retain the above copyright
26 ** notice, this list of conditions and the following disclaimer.
27 ** * Redistributions in binary form must reproduce the above copyright
28 ** notice, this list of conditions and the following disclaimer in
29 ** the documentation and/or other materials provided with the
30 ** distribution.
31 ** * Neither the name of The Qt Company Ltd nor the names of its
32 ** contributors may be used to endorse or promote products derived
33 ** from this software without specific prior written permission.
34 **
35 **
36 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
37 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
39 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
40 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
43 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
47 **
48 ** $QT_END_LICENSE$
49 **
50 ****************************************************************************/
51 
55 
61 
68 
70  std::uniform_real_distribution dist(1, 2.5);
71  return dist(*QRandomGenerator::global());
73 
75  std::seed_seq sseq(seedBuffer, seedBuffer + len);
78 
80  std::seed_seq sseq(begin, end);
83 
85  while (z--)
88 
90  std::generate(begin, end, [this]() { return generate(); });
92 
96 
99  list.resize(16);
102 
107 
110  return std::generate_canonical<qreal, std::numeric_limits<qreal>::digits>(rd);
112 
114  return generateDouble() * highest;
116 
120 
122  quint32 v = QRandomGenerator::global()->bounded(1000, 2000);
124 
128 
130  qint64 value = QRandomGenerator64::global()->generate() & std::numeric_limits<qint64>::max();
static QColor fromRgb(QRgb rgb) noexcept
Definition: qcolor.cpp:2366
qsizetype size() const noexcept
Definition: qlist.h:414
pointer data()
Definition: qlist.h:442
void resize(qsizetype size)
Definition: qlist.h:420
The QRandomGenerator64 class allows one to obtain 64-bit random values from a high-quality,...
Definition: qrandom.h:245
static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64 * global()
Definition: qrandom.cpp:1170
quint64 generate()
Definition: qrandom.h:250
The QRandomGenerator class allows one to obtain random values from a high-quality Random Number Gener...
Definition: qrandom.h:57
quint32 generate()
Definition: qrandom.h:84
static Q_DECL_CONST_FUNCTION QRandomGenerator * global()
Definition: qrandom.h:311
quint64 generate64()
Definition: qrandom.h:89
double bounded(double highest)
Definition: qrandom.h:108
void fillRange(UInt *buffer, qsizetype count)
Definition: qrandom.h:177
auto generate(StringRef generatorName, SourceLineInfo const &lineInfo, L const &generatorExpression) -> decltype(std::declval< decltype(generatorExpression())>().get())
Definition: catch_p_p.h:4085
EGLOutputLayerEXT EGLint EGLAttrib value
unsigned int quint32
Definition: qglobal.h:288
long long qint64
Definition: qglobal.h:298
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLuint GLuint end
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLenum array
Definition: qopenglext.h:7028
GLenum GLsizei len
Definition: qopenglext.h:3292
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
QRandomGenerator prng2(1234)
QList< quint32 > list
[8]
Q_ASSERT(prng1.generate()==prng2.generate())
return generateDouble() *highest
[11]
QRandomGenerator64 rd
[10]
std::seed_seq sseq(seedBuffer, seedBuffer+len)
[3]
QRandomGenerator prng1(1234)
[0]
QRandomGenerator generator(sseq)
std::uniform_real_distribution dist(1, 2.5)
[2]