qt6-bb10/tests/auto/corelib
Thiago Macieira 21d3916817 QRandomGenerator: add 64-bit bounded() versions
Unlike the 32-bit version, we can't go to a bigger integer type to do
the multiplication with. So instead accept looping. Both libstdc++ and
libc++ implement std::uniform_int_distribution this way anyway, but in a
far more complex way.

There is no looping if the "highest" is a power of two. The worst-case
scenario is when "highest" is one past a power of two (like 65). In that
case, we'll loop until the number is in range. Since all bits have equal
probability of being zero or one, there's a 50-50 chance that the most
significant useful bit will be set[*], in which case we'll need to loop
and we again get the same probability. So on average, we only need two
iterations to get an acceptable result.

[*] There's also a possibility that the other bits are such that the
number is still in range. For 65, we'd need the other 5 bits to be zero
(64 is a valid result), but the probability of that is only 1/2^5 =
3.125%. The bigger "highest" is, the closer we get to zero, so
approximate by saying that never happens and instead calculate that the
most significant useful bit is the controlling one.

[ChangeLog][QtCore][QRandomGenerator] Added 64-bit versions of the
bounded() functions. They are useful in conjunction with Qt 6's 64-bit
container sizes, so code that used to call bounded(list.size()) in Qt 5
will continue to compile and work in Qt 6.

Fixes: QTBUG-86318
Change-Id: I3eb349b832c14610895efffd16356927fe78fd02
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2020-10-20 22:45:06 -07:00
..
animation Remove timeStep parameter from QAnimationDrive::advanceAnimation 2020-10-13 08:44:42 +02:00
global QRandomGenerator: add 64-bit bounded() versions 2020-10-20 22:45:06 -07:00
io Add function to access QLockFile's file name 2020-10-18 20:16:38 +02:00
itemmodels Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
kernel Use qmetaobject_p.h's MetaObjectFlag in QMetaObjectBuilder 2020-10-20 12:03:44 +02:00
mimetypes CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
plugin CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
serialization Fix some compiler warnings from tests 2020-10-16 13:53:04 +02:00
text Tidy up tst_QLocale::ctor(), reduce needless repetition 2020-10-19 17:44:43 +02:00
thread Drop constexpr from QAtomicTraits::isLockFree() 2020-10-20 10:49:30 +02:00
time Fix blatant typo in QTimeZone test 2020-10-19 17:44:32 +02:00
tools Auto tests: Fix some MSVC warnings about integer conversions 2020-10-21 07:31:27 +02:00
.prev_CMakeLists.txt Move QStateMachine from QtCore to QtScxml 2020-08-24 20:10:25 +02:00
CMakeLists.txt Move QStateMachine from QtCore to QtScxml 2020-08-24 20:10:25 +02:00
corelib.pro Move QStateMachine from QtCore to QtScxml 2020-08-24 20:10:25 +02:00