Skip to content

Instantly share code, notes, and snippets.

@rogerwelin
Last active February 9, 2021 18:28
Show Gist options
  • Save rogerwelin/458233f38e49c6ae824b9ae8d4408b72 to your computer and use it in GitHub Desktop.
Save rogerwelin/458233f38e49c6ae824b9ae8d4408b72 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/rand"
"time"
)
func returnRandom(value int) string {
stringArr := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T"}
newString := ""
for i := 0; i <= value; i++ {
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
randIndex := r1.Intn(len(stringArr))
newString = newString + stringArr[randIndex]
}
return newString
}
func main() {
val := returnRandom(12)
fmt.Println(val)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment