github.com/searKing/golang/go@v1.2.117/crypto/rand/string_math.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package rand 6 7 // take in a character set and a length and will generate a random string using that character set. 8 func StringMathWithCharset(length int, charset string) string { 9 10 b := make([]byte, length) 11 for i := range b { 12 b[i] = charset[seededRandMath.Intn(len(charset))] 13 } 14 return string(b) 15 } 16 17 // only take in a length, and will use a default characters set to generate a random string 18 func StringMath(length int) string { 19 return StringMathWithCharset(length, CharsetAlphaNum) 20 }