github.com/imannamdari/v2ray-core/v5@v5.0.5/app/router/strategy_random.go (about) 1 package router 2 3 import ( 4 "github.com/imannamdari/v2ray-core/v5/common" 5 "github.com/imannamdari/v2ray-core/v5/common/dice" 6 ) 7 8 // RandomStrategy represents a random balancing strategy 9 type RandomStrategy struct{} 10 11 func (s *RandomStrategy) GetPrincipleTarget(strings []string) []string { 12 return strings 13 } 14 15 func (s *RandomStrategy) PickOutbound(candidates []string) string { 16 count := len(candidates) 17 if count == 0 { 18 // goes to fallbackTag 19 return "" 20 } 21 return candidates[dice.Roll(count)] 22 } 23 24 func init() { 25 common.Must(common.RegisterConfig((*StrategyRandomConfig)(nil), nil)) 26 }