Well, first of all, it should be 5, not 4 (I don't know what I was thinking).

rand() % 5 gives a random numbe between 0 and 4
Adding 1 puts it between 1 and 5
Multiplying by 2 gives eitehr 2, 4, 6, 8, or 10