github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/hack/integration-cli-on-swarm/agent/master/set.go (about)

     1  package main
     2  
     3  import (
     4  	"math/rand"
     5  )
     6  
     7  // chunkStrings chunks the string slice
     8  func chunkStrings(x []string, numChunks int) [][]string {
     9  	var result [][]string
    10  	chunkSize := (len(x) + numChunks - 1) / numChunks
    11  	for i := 0; i < len(x); i += chunkSize {
    12  		ub := i + chunkSize
    13  		if ub > len(x) {
    14  			ub = len(x)
    15  		}
    16  		result = append(result, x[i:ub])
    17  	}
    18  	return result
    19  }
    20  
    21  // shuffleStrings shuffles strings
    22  func shuffleStrings(x []string, seed int64) {
    23  	r := rand.New(rand.NewSource(seed))
    24  	for i := range x {
    25  		j := r.Intn(i + 1)
    26  		x[i], x[j] = x[j], x[i]
    27  	}
    28  }