# rand()

This is a discussion on rand() within the C Programming forums, part of the General Programming Boards category; Hi All What does this code mean? Code: if((rand() % xincrease) == 0) AddLetter(); (The code of the if statement) ...

1. ## rand()

Hi All

What does this code mean?

Code:
```if((rand() % xincrease) == 0)
(The code of the if statement)

Thanx

2. rand() returns pseudorandom value from 0 to RAND_MAX inclusive

a % b gives reminder for division a to b

if reminder is zero - it means a == b * m for some m

3. Will increasing xincrease (ie, 'b') increase the probability of the statement being true?

4. >Will increasing xincrease (ie, 'b') increase the probability of the statement being true?

No, decreasing it will increase the probability of the statement being true.

rand() % 1 == 0, true for every value from rand()
rand() % 2 == 0, true for every 2nd value from rand()
rand() % 3 == 0, true for every 3rd value from rand()
rand() % n == 0, true for every n:th value from rand()