go-zero/zrpc/internal/resolver/subset.go
2021-02-09 13:50:21 +08:00

15 lines
222 B
Go

package resolver
import "math/rand"
func subset(set []string, sub int) []string {
rand.Shuffle(len(set), func(i, j int) {
set[i], set[j] = set[j], set[i]
})
if len(set) <= sub {
return set
}
return set[:sub]
}