Skip to content

Instantly share code, notes, and snippets.

@pgilad pgilad/main.go
Created Aug 8, 2018

Embed
What would you like to do?
Generate stable random name from string (used to generate docker tag from git branch)
package main
import (
"fmt"
"hash/fnv"
"math/rand"
"os"
"github.com/docker/docker/pkg/namesgenerator"
)
func hash(s string) uint64 {
alg := fnv.New64a()
alg.Write([]byte(s))
return alg.Sum64()
}
func main() {
branch := os.Args[1]
seed := int64(hash(branch))
rand.Seed(seed)
fmt.Println(namesgenerator.GetRandomName(0))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.