Merge pull request #15126 from LK4D4/global_rand

Use global random *rand.Rand instance in pkg
This commit is contained in:
Arnaud Porterie 2015-07-29 17:36:25 -07:00
commit 4991aad4df
2 changed files with 2 additions and 5 deletions

View file

@ -2,7 +2,6 @@ package namesgenerator
import ( import (
"fmt" "fmt"
"math/rand"
"github.com/docker/docker/pkg/random" "github.com/docker/docker/pkg/random"
) )
@ -354,14 +353,13 @@ var (
// Ada Yonath - an Israeli crystallographer, the first woman from the Middle East to win a Nobel prize in the sciences. https://en.wikipedia.org/wiki/Ada_Yonath // Ada Yonath - an Israeli crystallographer, the first woman from the Middle East to win a Nobel prize in the sciences. https://en.wikipedia.org/wiki/Ada_Yonath
"yonath", "yonath",
} }
rnd = rand.New(random.NewSource())
) )
// GetRandomName generates a random name from the list of adjectives and surnames in this package // GetRandomName generates a random name from the list of adjectives and surnames in this package
// formatted as "adjective_surname". For example 'focused_turing'. If retry is non-zero, a random // formatted as "adjective_surname". For example 'focused_turing'. If retry is non-zero, a random
// integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3` // integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3`
func GetRandomName(retry int) string { func GetRandomName(retry int) string {
rnd := random.Rand
begin: begin:
name := fmt.Sprintf("%s_%s", left[rnd.Intn(len(left))], right[rnd.Intn(len(right))]) name := fmt.Sprintf("%s_%s", left[rnd.Intn(len(left))], right[rnd.Intn(len(right))])
if name == "boring_wozniak" /* Steve Wozniak is not boring */ { if name == "boring_wozniak" /* Steve Wozniak is not boring */ {

View file

@ -14,9 +14,8 @@ func GenerateRandomAlphaOnlyString(n int) string {
// make a really long string // make a really long string
letters := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") letters := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]byte, n) b := make([]byte, n)
r := rand.New(random.NewSource())
for i := range b { for i := range b {
b[i] = letters[r.Intn(len(letters))] b[i] = letters[random.Rand.Intn(len(letters))]
} }
return string(b) return string(b)
} }