From 627d5ea83be1ad9a702c40a31d0d633e461faba1 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Wed, 8 Apr 2015 18:09:55 -0700 Subject: [PATCH] names-generator: use local random instance Instead of seeding/polluting the global random instance, creating a local `rand.Random` instance which provides the same level of randomness. Signed-off-by: Ahmet Alp Balkan --- namesgenerator/names-generator.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/namesgenerator/names-generator.go b/namesgenerator/names-generator.go index 38dced3..b33e8c2 100644 --- a/namesgenerator/names-generator.go +++ b/namesgenerator/names-generator.go @@ -302,19 +302,19 @@ 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 "yonath", } + + rnd = rand.New(rand.NewSource(time.Now().UnixNano())) ) func GetRandomName(retry int) string { - rand.Seed(time.Now().UnixNano()) - begin: - name := fmt.Sprintf("%s_%s", left[rand.Intn(len(left))], right[rand.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 */ { goto begin } if retry > 0 { - name = fmt.Sprintf("%s%d", name, rand.Intn(10)) + name = fmt.Sprintf("%s%d", name, rnd.Intn(10)) } return name }