Skip to content

Commit

Permalink
Switching to fastrandn, which avoids modulo
Browse files Browse the repository at this point in the history
  • Loading branch information
panmari committed Sep 26, 2023
1 parent e3cb76b commit 5d2f798
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (

// fastrand is a fast thread local random function.
//
//go:linkname fastrand runtime.fastrand
func fastrand() uint32
//go:linkname fastrandn runtime.fastrandn
func fastrandn(n uint32) uint32

// randi returns either i1 or i2 randomly.
func randi(i1, i2 uint) uint {
if fastrand()%2 == 0 {
if fastrandn(2) == 0 {
return i1
}
return i2
Expand Down

0 comments on commit 5d2f798

Please sign in to comment.