go-zero/zrpc/resolver/internal/subset.go

15 lines
222 B
Go
Raw Normal View History

package internal
2020-08-06 23:06:26 +08:00
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
}
2021-02-09 13:50:21 +08:00
return set[:sub]
2020-08-06 23:06:26 +08:00
}