package randstr

import (
	"math/rand/v2"
)

const (
	LowercaseAlphabetCharset = "abcdefghijklmnopqrstuvwxyz"
	AlphabetCharset          = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	AlphanumericCharset      = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)

func GenWithCharset(length int, charset string) string {
	b := make([]byte, length)
	for i := range b {
		// Use system default rand seed.
		// As of Go 1.22, math/rand's top-level functions (when not explicitly seeded) and the Go runtime use ChaCha8 for randomness.
		//nolint:gosec
		b[i] = charset[rand.IntN(len(charset))]
	}
	return string(b)
}
