Currently I'm using a very fast XorShift algorithm:
inline uint r() {
static uint y = 2463534242u; // seed
y ^= (y<<13);
y ^= (y>>17);
y ^= (y<<5);
return y;
}
Now I want to generate an integer from interval [0, n). Of course I can do this:
r() % n
But this is slow. Is there a faster way?
PS A small inequalities in probabilities of different numbers in the interval are acceptable.