"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.
"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.
"He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson