| 1 |
package tygoja |
| 2 |
|
| 3 |
import ( |
| 4 |
mathRand "math/rand" |
| 5 |
"time" |
| 6 |
) |
| 7 |
|
| 8 |
const defaultRandomAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
| 9 |
|
| 10 |
func init() { |
| 11 |
mathRand.Seed(time.Now().UnixNano()) |
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
func PseudorandomString(length int) string { |
| 17 |
return PseudorandomStringWithAlphabet(length, defaultRandomAlphabet) |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
func PseudorandomStringWithAlphabet(length int, alphabet string) string { |
| 23 |
b := make([]byte, length) |
| 24 |
max := len(alphabet) |
| 25 |
|
| 26 |
for i := range b { |
| 27 |
b[i] = alphabet[mathRand.Intn(max)] |
| 28 |
} |
| 29 |
|
| 30 |
return string(b) |
| 31 |
} |