cynosura cynosura - 1 year ago 65
C++ Question

c++ - rand() between number which are multiple

So I would like to have a random number that is a multiple of 32, so, 32, 64, 96, 128...

rand() return a number which is not always a multiple of 32 of course.
How could I proceed ?

Answer Source

if you are using rand() (wich is not suggested, use the C++11 header<random>) you could just multiply the values with 32:

int num = (rand() % 1001) * 32; //random number between 0 - 32000 (always a multiple of 32)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download