Skip to content

Commit

Permalink
Append UUID at the end of name
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr committed Apr 30, 2024
1 parent 40883b2 commit b7acbe4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions utility/random.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utility

import (
"github.com/google/uuid"
"math/rand"
"time"
)
Expand Down Expand Up @@ -40,9 +41,14 @@ var nouns = [...]string{
"shore", "cavern", "gorge", "spring", "arrow", "heap",
}

// RandomName generates a Heroku-style random name for instances/clusters/etc
// RandomName generates a Heroku-style random name for instances/clusters/etc and appends a short UUID
func RandomName() string {
rand.Seed(time.Now().Unix())
rand.Seed(time.Now().UnixNano()) // Seed the random number generator

return adjectives[rand.Intn(len(adjectives))] + "-" + nouns[rand.Intn(len(nouns))]
// Generate a random adjective and noun combination
name := adjectives[rand.Intn(len(adjectives))] + "-" + nouns[rand.Intn(len(nouns))]

// Generate a UUID and truncate it to the first 8 characters
shortUUID := uuid.New().String()[:8]
return name + "-" + shortUUID
}

0 comments on commit b7acbe4

Please sign in to comment.