Yes, this is what I am referring to. Your method still has the quantization error described in my paper. If r is a power of 2, then you can simply use (C language:)
y = x & (r-1);
where x is random bits. If r is not a power of 2, then you can use the method you describe, or this method which is faster: y = ((uint32_t)x * (uint64_t)r) >> 32; Both methods have the same quantization error. If you want exactness then use the rejection method described in my paper (which will be published in the next issue of Journal of Modern Applied Statistical Methods). |