
C++ → Generating pseudo-random numbers in Qt (QRandomGenerator)
This note is a small addition to the article Generating pseudo-random numbers using the random STD library . The author omitted one of the useful functions of the QRandomGenerator class in it. The generator implementation is as follows:
QRandomGenerator *rg = QRandomGenerator::global(); for(int i = 0; i < 10; i++) { qDebug() << rg->bounded(1, 10); }
The global() function returns a pointer to a ready-to-run random number generator. An alternative to it is the system () function, which implements the possibilities for generating random numbers embedded in the operating system. The bounded(a, b) function returns a random number from a to b. The following functions are also available to us: generateDouble() - returns one random number from the range from 0 to 1, generate() and generate64() - return a random 32 and 64 bit random number, respectively. All of the listed functions will return a new sequence of numbers each time they are run/called.
In my opinion, such a toolkit is able to cover all the needs of an average programmer for generating random numbers without connecting third-party libraries.

Qt → Qt/C++ - Tutorial 074. Generating pseudo-random numbers, using STD library random
qsrand, QRandomGenerator, Qt, Random, C++11, qrand
Generating random numbers may be needed, for example, to calculate weapon damage in a computer game or to represent a graph from random numbers.
Qt provides the qrand function for generating random numbers, and also, starting with Qt 5.10 , the QRandomGenerator class.
Let's see how random values can be obtained in Qt, and how random they are.
Fornex
Let me recommend you a great European Fornex hosting.
Fornex has proven itself to be a stable host over the years.
For Django projects I recommend VPS hosting
Following the link you will receive a 5% discount on shared hosting services, dedicated servers, VPS and VPN
View HostingShare on social networks
Donate
The EVILEG project has switched to a non-commercial basis and will develop solely on the enthusiasm of the site creator, the enthusiasm of users, donations and the hosting referral system
Thank you for your support
Available ways to support the project
PayPal
PatreonYandex.MoneyMore