how i create that i get random number betwen 1 and 32?
now command a = qrand() every time I run the program, it always returns the same numbers.
how i create that i get random number betwen 1 and 32?
now command a = qrand() every time I run the program, it always returns the same numbers.
You cannot generate random numbers with a function. Only pseudo-random numbers. qrand returns a deterministic sequence of pseudo-random numbers; the sequence is the same each time because you aren't seeding the sequence differently. You do this with qsrand(uint); you can use a time value for the argument if you want a different result each time.
This is true of all such functions, unless they are tied to a hardware source of random numbers such as those available on some CPUs. In general, such truly random sources are as necessary as they are rare.
It is not possible to generate a perfect randon number sequence just using software, as software behaves always in a predictable pattern.
You can try time / second / milli second as a randonmize paramter to get better randon sequence.![]()
Put this line In main()With this line every time pseudo-random generator will be initialised with another sequence.Qt Code:
To copy to clipboard, switch view to plain text mode
Bookmarks