Skip to content

Instantly share code, notes, and snippets.

@asim
Created June 26, 2020 13:52
Show Gist options
  • Save asim/6c698dd199aa83a094c3657d27e271b7 to your computer and use it in GitHub Desktop.
Save asim/6c698dd199aa83a094c3657d27e271b7 to your computer and use it in GitHub Desktop.
package rand
import (
"math/rand"
"time"
)
const charset = "abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var seededRand *rand.Rand = rand.New(
rand.NewSource(time.Now().UnixNano()))
func StringWithCharset(length int, charset string) string {
b := make([]byte, length)
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
}
return string(b)
}
func String(length int) string {
return StringWithCharset(length, charset)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment