tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: A Fast Alternative to Modulo Reduction



On 2016-12-16 09:09, Abhinav Upadhyay wrote:
I came across an interesting article [1] which talks about a faster
alternative to the mod operation (x % N) for mapping a number to a
fixed range, such as [0, N), which is common when we want to generate
random numbers within a given range, or map a hash value to a range of
indices in an array.

You shouldn't use mod with rand(3).
Use something like arc4random_uniform(3) instead (I note that the man page for it is missig on my netbsd-7, see arcrandon(3)).

Roy


Home | Main Index | Thread Index | Old Index