"using % (mod) is a little bit slow"

Another way is to AND the returned value with the number. Of course, it only works for powers of two, but

rand() % 2 == rand() & 1
rand() % 4 == rand() & 3
rand() % 8 == rand() & 7

etc.