Choose one number from two

How do I make my program choose a number/variable randomly?

rand from what I know generates a random number.
I wanted to upgrade my console app so:
if the "pick-number-randomly" function thingy picks 1, the hero will be granted 5% damage bonus, and if it's 2, the monster is granted 5% damage bonus.

I remember it from Lua it was like that:
math.random(1, 0)
if math.random=1 then

and so on.
rand() returns a number between 0 and RAND_MAX. If y--
actually, read this instead:
http://www.cplusplus.com/reference/clibrary/cstdlib/rand/
1
2
3
4
5
6
int v = rand()%2;
if (v == 0) {
   //HERO_BONUS
} else {
   //MONSTER_BONUS
}
Topic archived. No new replies allowed.