Merge pull request #960 from ahmetalpbalkan/random

scheduler/random: Use private instance of rand
This commit is contained in:
Victor Vieux 2015-06-15 18:13:20 -07:00
commit 077489a948
1 changed files with 5 additions and 3 deletions

View File

@ -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")