github.com/moleculer-go/moleculer@v0.3.3/strategy/random.go (about)

     1  package strategy
     2  
     3  import (
     4  	"math/rand"
     5  )
     6  
     7  // RoundRobinStrategy exposes the type as a strategy option
     8  type RandomStrategy struct {
     9  }
    10  
    11  func (randomStrategy RandomStrategy) Select(nodes []Selector) *Selector {
    12  	if len(nodes) == 0 {
    13  		return nil
    14  	}
    15  	// Returns a number among the indexes up to the length
    16  	// of the slice
    17  	return &nodes[rand.Intn(len(nodes))]
    18  }