Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "nearly-divisionless" Uint64n #3

Open
lukechampine opened this issue Oct 5, 2020 · 0 comments
Open

Implement "nearly-divisionless" Uint64n #3

lukechampine opened this issue Oct 5, 2020 · 0 comments

Comments

@lukechampine
Copy link
Owner

Uint64n uses the same approach as Go's math/rand: truncate the range [0, math.MaxUint64] to the nearest multiple of n, then resample until we get a value within the truncated range and take the modulus. This is fairly fast, and easy to understand, but there's a faster approach that requires no divisions in the common case (whereas the current approach requires at least two). Indeed, math/rand adopted this approach for its Shuffle API (other APIs can't be changed due to the compatibility promise).

For Hacktoberfest, I'm inviting anyone to implement Lemire's algorithm for the Uint64n function. I expect that the speedup will be relatively small, but frand is all about speed, so we might as well push it to the limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant