How do I set a minimum on my rand?

spot=(rand() % 6 ) +spot;

What do i put so that it doesnt go below 1?
You add one
rand() % 6 + 1 This will give a random number in the range 1-6.
closed account (zb0S216C)
I don't think there is a way. Try using an if condition:

1
2
if(((spot = (rand() % 6)) + spot) < 1)
            spot = 1;

Edit: Peter87's solution is better :)

Wazzak
Last edited on
Ty peter that worked perfectly
Topic archived. No new replies allowed.