strategy_random.go 351 B

1234567891011121314151617
  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) PickOutbound(candidates []string) string {
  8. count := len(candidates)
  9. if count == 0 {
  10. // goes to fallbackTag
  11. return ""
  12. }
  13. return candidates[dice.Roll(count)]
  14. }