set.go 559 B

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