Skip to content

Commit

Permalink
fix: make sure nextInt returns correct int rng value
Browse files Browse the repository at this point in the history
  • Loading branch information
lixun910 authored Jun 29, 2023
1 parent d481d71 commit 6ba7bf3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion rng.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Xoroshiro128Random
if (n <=0) return 0;
int r = (int)((n & -n) == n ? (nextLong() & n) - 1 // power of two
: (unsigned long long)(((unsigned long long)nextLong() >> 32) * n) >> 32);
return r < 0 ? 0 : r;
return r >= 0 && r < n ? r : 0;
}

long long nextLong() {
Expand Down

0 comments on commit 6ba7bf3

Please sign in to comment.