mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
29 lines
559 B
Go
29 lines
559 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"math/rand"
|
||
|
)
|
||
|
|
||
|
// chunkStrings chunks the string slice
|
||
|
func chunkStrings(x []string, numChunks int) [][]string {
|
||
|
var result [][]string
|
||
|
chunkSize := (len(x) + numChunks - 1) / numChunks
|
||
|
for i := 0; i < len(x); i += chunkSize {
|
||
|
ub := i + chunkSize
|
||
|
if ub > len(x) {
|
||
|
ub = len(x)
|
||
|
}
|
||
|
result = append(result, x[i:ub])
|
||
|
}
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
// shuffleStrings shuffles strings
|
||
|
func shuffleStrings(x []string, seed int64) {
|
||
|
r := rand.New(rand.NewSource(seed))
|
||
|
for i := range x {
|
||
|
j := r.Intn(i + 1)
|
||
|
x[i], x[j] = x[j], x[i]
|
||
|
}
|
||
|
}
|