What is the method of generating random numbers by Qt?
This article mainly introduces "what is the method of Qt generating random numbers". In daily operation, I believe many people have doubts about what is the method of Qt generating random numbers. The editor consulted various materials and sorted out simple and easy operation methods. I hope to help you answer the doubts of "what is the method of Qt generating random numbers"! Next, please follow the small series to learn together!
1. generating a random number
Random number generation mainly uses the functions qsrand and qrand, these two functions in #include, qsrand is used to set a seed, the seed is qrand generate random number starting value. For example, qsrand(10), set 10 as the seed, then qrand generates random numbers between [10, 32767]. If qsrand () has not been called before qrand (), qrand() automatically calls qsrand(1), i.e., the system defaults to 1 as the starting value for random numbers. Random numbers generated using the same seed.
The following code generates 10 random numbers between [0,9].
void generateRandomNumber(){ qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); for(int i=0; i