Documentation
¶
Index ¶
- func GetStringBuilder() *strings.Builder
- func PickFromList[T any](rng *rand.Rand, list []T) T
- func PickFromMapKeys[K comparable, V any](rng *rand.Rand, m map[K]V) K
- func PickFromMapValues[K comparable, V any](rng *rand.Rand, m map[K]V) V
- func PutStringBuilder(sb *strings.Builder)
- func RandomASCIICharacter(rng *rand.Rand) string
- func RandomAlphanumeric(rng *rand.Rand, upperCase bool) string
- func RandomBool(rng *rand.Rand, probTrue float64) bool
- func RandomDateTime(rng *rand.Rand, from time.Time, to time.Time) time.Time
- func RandomDigit(rng *rand.Rand) int
- func RandomFloat(rng *rand.Rand) float64
- func RandomFloatBetween(rng *rand.Rand, decimals int, decimalsExact bool, min, max float64) float64
- func RandomInteger[T int | int32 | int64 | uint | uint32 | uint64](rng *rand.Rand) T
- func RandomIntegerBetween[T int | int32 | int64 | uint | uint32 | uint64](rng *rand.Rand, min, max T) T
- func RandomLetter(rng *rand.Rand, upperCase bool) string
- func RandomSeed() uint64
- func RandomString(rng *rand.Rand, length int, upperCase bool) string
- func RandomStringTemplate(rng *rand.Rand, template string) string
- func ShuffleString(rng *rand.Rand, s string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetStringBuilder ¶
func PickFromList ¶
PickFromList selects a random element from the provided list using the given random number generator. If the list is empty, it returns the zero value for the type T.
func PickFromMapKeys ¶
func PickFromMapKeys[K comparable, V any](rng *rand.Rand, m map[K]V) K
PickFromMapKeys selects a random key from the provided map using the given random number generator. If the map is empty, it returns the zero value for the key type K.
func PickFromMapValues ¶
func PickFromMapValues[K comparable, V any](rng *rand.Rand, m map[K]V) V
PickFromMapValues selects a random value from the provided map using the given random number generator. If the map is empty, it returns the zero value for the value type V.
func PutStringBuilder ¶
func RandomASCIICharacter ¶
RandomASCIICharacter generates a random printable ASCII character (from 32 to 126) using the provided random number generator.
func RandomAlphanumeric ¶
RandomAlphanumeric generates a random alphanumeric character (0-9, a-z, A-Z) based on the upperCase parameter using the provided random number generator.
func RandomBool ¶
RandomBool generates a random boolean value based on the provided probability of being true using the given random number generator. probTrue should be a value between 0.0 and 1.0, where 0.0 means always false and 1.0 means always true.
func RandomDateTime ¶
RandomDateTime generates a random time between the provided 'from' and 'to' times using the provided random number generator.
func RandomDigit ¶
RandomDigit generates a random digit (0-9) using the provided random number generator.
func RandomFloat ¶
func RandomFloatBetween ¶
RandomFloatBetween generates a random float between min and max (inclusive) with the specified number of decimal places using the provided random number generator. If min is greater than max, they will be swapped to ensure a valid range. If max is 0, it will be treated as math.MaxFloat64. If decimalsExact is true, the result will be rounded to the specified 'decimals' decimal places. If false, the result may have up to 'decimals' decimal places.
func RandomInteger ¶
RandomInteger generates a random integer of the specified type using the provided random number generator.
func RandomIntegerBetween ¶
func RandomIntegerBetween[T int | int32 | int64 | uint | uint32 | uint64](rng *rand.Rand, min, max T) T
RandomIntegerBetween generates a random integer between min and max (inclusive) using the provided random number generator. If min is greater than max, they will be swapped to ensure a valid range. If max is 0, it will be treated as the maximum value for the type T (e.g., math.MaxInt for int).
func RandomLetter ¶
RandomLetter generates a random letter (A-Z or a-z) based on the upperCase parameter using the provided random number generator.
func RandomSeed ¶
func RandomSeed() uint64
RandomSeed creates a unique seed by combining the current time, process ID, and an atomic counter, to minimize the chances of collision.
func RandomString ¶
RandomString generates a random string of the specified length and case using the provided random number generator. If upperCase is true, the string will contain only uppercase letters. The length is capped at 'stringLength' to prevent excessive memory usage.
func RandomStringTemplate ¶
RandomStringTemplate generates a random string filling in the provided template, where: - '\d' is replaced with a random digit (0-9) - '\a' is replaced with a random alphanumeric character (0-9, a-z) - '\A' is replaced with a random alphanumeric character (0-9, A-Z) - '\l' is replaced with a random lowercase letter (a-z) - '\L' is replaced with a random uppercase letter (A-Z) - '\.' is replaced with a random printable ASCII 32-126 character Any other characters in the template are left unchanged.
Types ¶
This section is empty.