Skip to content

Commit 5d2f798

Browse files
committed
Switching to fastrandn, which avoids modulo
1 parent e3cb76b commit 5d2f798

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import (
99

1010
// fastrand is a fast thread local random function.
1111
//
12-
//go:linkname fastrand runtime.fastrand
13-
func fastrand() uint32
12+
//go:linkname fastrandn runtime.fastrandn
13+
func fastrandn(n uint32) uint32
1414

1515
// randi returns either i1 or i2 randomly.
1616
func randi(i1, i2 uint) uint {
17-
if fastrand()%2 == 0 {
17+
if fastrandn(2) == 0 {
1818
return i1
1919
}
2020
return i2

0 commit comments

Comments
 (0)