Skip to content

Commit

Permalink
limit random int to 32 bits to be compatible with 32 bit systems
Browse files Browse the repository at this point in the history
  • Loading branch information
typerat committed Apr 5, 2021
1 parent b324bfb commit 36a297c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions random.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func rand(seed interface{}) int {
// hash input data
hash := sha256.Sum256(buf)

// convert hash to int
i := binary.BigEndian.Uint64(hash[:8])
i &= math.MaxInt64
// convert hash to int32 (to be compatible with 32bit int)
i := binary.BigEndian.Uint32(hash[:4])
i &= math.MaxInt32

return int(i)
}

0 comments on commit 36a297c

Please sign in to comment.