I tried to remove the integer from the generated string with regex but this will not give me the length within the range required( many will be less than the minimum )
package main
import (
"fmt"
"log"
"math/rand"
"regexp"
"time"
)
func randomString(length int) string {
rand.Seed(time.Now().UnixNano())
b := make([]byte, length)
rand.Read(b)
return fmt.Sprintf("%x", b)[:length]
}
func randomLength(minL, maxL int) int {
rand.Seed(time.Now().UnixNano())
return rand.Intn(maxL-minL) + minL
}
func main() {
reg, err := regexp.Compile("[^a-zA-Z]+")
if err != nil {
log.Fatal(err)
}
for i := 0; i < 10; i++ {
processedString := reg.ReplaceAllString(randomString(randomLength(8, 16)), "")
println(processedString)
}
}
Edit: when I searched for the question I missed detailed @icza answer in that question.