math/rand.Intn(n) generates a `value`, (#83)

which has the following properties `value >=0 && value < n`.

I previously thought it was `value >=0 && value <= n`.
pull/85/head
lu4p 4 years ago committed by GitHub
parent c51e08ef37
commit 0dd97ed0fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,11 +4,12 @@ import (
"go/ast" "go/ast"
"go/token" "go/token"
mathrand "math/rand" mathrand "math/rand"
ah "mvdan.cc/garble/internal/asthelper" ah "mvdan.cc/garble/internal/asthelper"
) )
const ( const (
maxChunkSize = 5 maxChunkSize = 4
minCaseCount = 3 minCaseCount = 3
) )
@ -26,7 +27,7 @@ func splitIntoRandomChunks(data []byte) [][]byte {
var chunks [][]byte var chunks [][]byte
for len(data) > 0 { for len(data) > 0 {
chunkSize := 1 + mathrand.Intn(maxChunkSize-1) chunkSize := 1 + mathrand.Intn(maxChunkSize)
if chunkSize > len(data) { if chunkSize > len(data) {
chunkSize = len(data) chunkSize = len(data)
} }

Loading…
Cancel
Save