strategy_random.go 443 B

123456789101112131415161718192021
  1. package router
  2. import (
  3. "github.com/v2fly/v2ray-core/v4/common/dice"
  4. )
  5. // RandomStrategy represents a random balancing strategy
  6. type RandomStrategy struct{}
  7. func (s *RandomStrategy) GetPrincipleTarget(strings []string) []string {
  8. return strings
  9. }
  10. func (s *RandomStrategy) PickOutbound(candidates []string) string {
  11. count := len(candidates)
  12. if count == 0 {
  13. // goes to fallbackTag
  14. return ""
  15. }
  16. return candidates[dice.Roll(count)]
  17. }