Last active
February 9, 2021 18:28
-
-
Save rogerwelin/458233f38e49c6ae824b9ae8d4408b72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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