rand

what is the base number of rand?
i cant rand a number from 5-7 in my program

1
2
player_damage=7;
rand_damage= rand() % player_damage + 5; 
closed account (48T7M4Gy)
a) rand() generates a random number between 0 and 32,767 (at least)
b) rand() % 7 generates a random number between 0 and 6

c) So, rand() % 7 + 5 generates a random number between (0+5) = 5 and (6+5) = 11
d) From that you should be able to write a simple sum to generate a random number between 5 and 7. Hint: 5= 0+5, 6=1+5 and 7=2+5


Topic archived. No new replies allowed.