cynosura - 8 months ago 39

C++ Question

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

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)
```

Source (Stackoverflow)