diff --git a/scheduler/strategy/random.go b/scheduler/strategy/random.go index c7a08d3c51..2aac01ff6e 100644 --- a/scheduler/strategy/random.go +++ b/scheduler/strategy/random.go @@ -10,11 +10,13 @@ import ( ) // RandomPlacementStrategy randomly places the container into the cluster. -type RandomPlacementStrategy struct{} +type RandomPlacementStrategy struct { + r *rand.Rand +} // Initialize is exported func (p *RandomPlacementStrategy) Initialize() error { - rand.Seed(time.Now().UTC().UnixNano()) + p.r = rand.New(rand.NewSource(time.Now().UTC().UnixNano())) return nil } @@ -26,7 +28,7 @@ func (p *RandomPlacementStrategy) Name() string { // PlaceContainer is exported func (p *RandomPlacementStrategy) PlaceContainer(config *cluster.ContainerConfig, nodes []*node.Node) (*node.Node, error) { if size := len(nodes); size > 0 { - return nodes[rand.Intn(size)], nil + return nodes[p.r.Intn(size)], nil } return nil, errors.New("No nodes running in the cluster")