Skip to content

Commit

Permalink
Do bit shifting with 64 bit precision (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesper-friis authored Sep 27, 2024
1 parent 213a063 commit a2f271b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils/rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,18 @@ static uint64_t rand_digits(uint64_t n)

/* odd random number for low order digit */
u = (rand_msws32_r(&s) % 8) * 2 + 1;
v = (1<<u);
v = (1L<<u);

/* get rest of digits */
for (m=60,c=0;m>0;) {
j = rand_msws32_r(&s); /* get 8 digit 32-bit random word */
for (i=0;i<32;i+=4) {
k = (j>>i) & 0xf; /* get a digit */
if (k!=0 && (c & (1<<k)) == 0) { /* not 0 and not previous */
c |= (1<<k);
if (k!=0 && (c & (1L<<k)) == 0) { /* not 0 and not previous */
c |= (1L<<k);
u |= (k<<m); /* add digit to output */
m -= 4;
if (m==24 || m==28) c = (1<<k) | v;
if (m==24 || m==28) c = (1L<<k) | v;
if (m==0) break;
}
}
Expand Down

0 comments on commit a2f271b

Please sign in to comment.