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

rnd.next(0ULL, -1ULL) overflow crashes #109

Open
yang-er opened this issue Apr 12, 2020 · 1 comment
Open

rnd.next(0ULL, -1ULL) overflow crashes #109

yang-er opened this issue Apr 12, 2020 · 1 comment

Comments

@yang-er
Copy link

yang-er commented Apr 12, 2020

to = 2^64-1, from = 0, therefore to - from + 1 = 2^64 = 0 for unsigned long long.

Is there any solutions to random in [0, 2^64-1] in one shot?

@naumazeredo
Copy link

naumazeredo commented Jun 5, 2020

By taking a look at testlib.h, unsigned long long next(unsigned long long n) is using long long next(long long n), so basically you can't reach 2^64-1.

To create your rnd.next for unsigned 64bits you can just modify nextBits to operate with unsigned long long all the way instead of long long (seed, multiplier, addend and mask are all unsigned long long so it's not a problem) and accept 64bits... I don't know why they add this limitation

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

No branches or pull requests

2 participants