forked from TrueCloudLab/rclone
lib/random: unify random string generation into random.String
This was factored from fstest as we were including the testing
enviroment into the main binary because of it.
This was causing opening the browser to fail because of 8243ff8bc8
.
This commit is contained in:
parent
72d5b11d1b
commit
5065c422b4
12 changed files with 63 additions and 65 deletions
22
lib/random/random.go
Normal file
22
lib/random/random.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Package random holds a few functions for working with random numbers
|
||||
package random
|
||||
|
||||
import "math/rand"
|
||||
|
||||
// String create a random string for test purposes
|
||||
func String(n int) string {
|
||||
const (
|
||||
vowel = "aeiou"
|
||||
consonant = "bcdfghjklmnpqrstvwxyz"
|
||||
digit = "0123456789"
|
||||
)
|
||||
pattern := []string{consonant, vowel, consonant, vowel, consonant, vowel, consonant, digit}
|
||||
out := make([]byte, n)
|
||||
p := 0
|
||||
for i := range out {
|
||||
source := pattern[p]
|
||||
p = (p + 1) % len(pattern)
|
||||
out[i] = source[rand.Intn(len(source))]
|
||||
}
|
||||
return string(out)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue