fix bug in knuth RNG (#1757)

* fix bug in knuth RNG

* real fix, thanks ManDude

* cleanup negation
This commit is contained in:
Matt Dallmeyer 2022-08-14 13:50:40 -07:00 committed by GitHub
parent 2313d35800
commit a77f8ae66d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,9 +60,9 @@
(val 0))
;; if ((bound & -bound) == bound) // i.e., bound is a power of 2
(if (= (logand bound (* -1 bound)) bound)
(if (= (logand bound (- bound)) bound)
;; return (int)((bound * (long)next(31)) >> 31);
(return (sar (* bound (knuth-rand-next 31)) 31))
(return (+ min (sar (imul64 bound (knuth-rand-next 31)) 31)))
)
;; do {