Qt and random numbers
-
Hi, Qt Developer Network!
My project have to create random "Shultz tables":http://www.st.vstour.info/ShultzTables.html
So it is my first try with qrand() and qsrand().
Can you help me and write howto write a code that will generate random number in diapason 1-25?
Thanks!
<body ></body>
-
-
Not sure what you need, I guess a random number between 1 and 25. I don't know if there is a way to limit qrand (different from MAX_RAND), but maybe you can iterate over qrand to get a limited value?
-
[quote author="fluca1978" date="1320931836"]... but maybe you can iterate over qrand to get a limited value?[/quote]
In this situation the best method, in my opinion is:
@
qrand() % 25 + 1
@ -
Well I thought that solution was implied, my bad.
-
Good solution!
-
Sorry for my post into such an old thread, but it must be:
@inline int rangedRand(unsigned int min, unsigned int max){
return (qrand() % (max+1-min)) + min;
}@ -