Documentation
¶
Index ¶
- func AnyInt() (int, error)
- func AnyInt32() (int32, error)
- func AnyInt64() (int64, error)
- func Base64(byteLen int) (string, error)
- func Bool() (bool, error)
- func Choice(choices ...any) (any, error)
- func Datetime() (time.Time, error)
- func Email(totalLength int) (string, error)
- func GetWithCustomCharset(length int, charset string) (string, error)
- func Hex(strLen int) (string, error)
- func Int32Range(minInclusive int32, maxInclusive int32) (int32, error)
- func Int64Range(minInclusive int64, maxInclusive int64) (int64, error)
- func IntRange(minInclusive int, maxInclusive int) (int, error)
- func MustAnyInt() int
- func MustAnyInt32() int32
- func MustAnyInt64() int64
- func MustBase64(byteLen int) string
- func MustBool() bool
- func MustChoice(choices ...any) any
- func MustDatetime() time.Time
- func MustEmail(totalLength int) string
- func MustGetWithCustomCharset(length int, charset string) string
- func MustHex(strLen int) string
- func MustInt32Range(minInclusive int32, maxInclusive int32) int32
- func MustInt64Range(minInclusive int64, maxInclusive int64) int64
- func MustIntRange(minInclusive int, maxInclusive int) int
- func MustNegativeInt32() int32
- func MustNegativeInt64() int64
- func MustPositiveInt32() int32
- func MustPositiveInt64() int64
- func MustShuffle(slice []any)
- func MustSlicePickMany(slice []any, chanceThreshold int) []any
- func MustSlicePickOne(slice []any) any
- func MustString(length int) string
- func MustStringSlice(sliceLength, minStrLen, maxStrLen int) []string
- func MustTimeInNearFuture() time.Time
- func MustTimeInNearPast() time.Time
- func NegativeInt32() (int32, error)
- func NegativeInt64() (int64, error)
- func PositiveInt32() (int32, error)
- func PositiveInt64() (int64, error)
- func Shuffle(slice []any) error
- func SlicePickMany(slice []any, chanceThreshold int) ([]any, error)
- func SlicePickOne(slice []any) (any, error)
- func String(length int) (string, error)
- func StringSlice(sliceLength int, minStrLen int, maxStrLen int) ([]string, error)
- func TimeInNearFuture() (time.Time, error)
- func TimeInNearPast() (time.Time, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyInt ¶
AnyInt returns a secure random int from the full range of int.
Returns:
- int: A random int in [-2147483647, 2147483648].
- error: An error if crypto/rand fails.
func AnyInt32 ¶
AnyInt32 returns a random int32 in the full int32 range.
Returns:
- int32: A random int32 in [-2147483647, 2147483648].
- error: An error if crypto/rand fails.
func AnyInt64 ¶
AnyInt64 returns a secure random int64 in the full int64 range.
Returns:
- int64: A random int64 in [-9223372036854775808, 9223372036854775807].
- error: An error if crypto/rand fails.
func Base64 ¶
Base64 returns a base64 encoded random string built from byteLen random bytes.
Parameters:
- byteLen: The length of the random bytes.
Returns:
- string: Base64 encoded random string.
- error: An error if crypto/rand fails.
func Choice ¶
Choice returns a random choice from the provided arguments.
Returns:
- any: A random choice from the provided arguments.
- error: An error if crypto/rand fails.
func Datetime ¶
Datetime returns a secure random time between year 1 and 9999.
Returns:
- time.Time: A random time between year 1 and 9999.
- error: An error if crypto/rand fails.
func Email ¶
Email returns a random email address of totalLength characters. The email is built as local@domain.com (5 characters reserved for "@" and ".com"). totalLength must be at least 6.
Returns:
- string: A random email address.
- error: An error if crypto/rand fails.
func GetWithCustomCharset ¶
GetWithCustomCharset returns a random string of length characters drawn from the provided charset.
Parameters:
- length: The length of the random string.
- charset: The characters to draw from.
Returns:
- string: A random string of length characters drawn from the provided charset.
- error: An error if crypto/rand fails.
func Hex ¶
Hex returns a random hexadecimal string of length strLen. strLen must be even or it will return an error.
Parameters:
- strLen: The length of the random hexadecimal string.
Returns:
- string: A random hexadecimal string of length strLen.
- error: An error if crypto/rand fails or strLen is not even.
func Int32Range ¶
Int32Range returns a secure random int32 in [minInclusive, maxInclusive].
Parameters: - minInclusive: The minimum value (inclusive). - maxInclusive: The maximum value (inclusive).
Returns:
- int32: A random int32 in [minInclusive, maxInclusive].
- error: An error if crypto/rand fails.
func Int64Range ¶
Int64Range returns a secure random int64 in [minInclusive, maxInclusive].
Parameters: - minInclusive: The minimum value (inclusive). - maxInclusive: The maximum value (inclusive).
Returns:
- int64: A random int64 in [minInclusive, maxInclusive].
- error: An error if crypto/rand fails.
func IntRange ¶
IntRange returns a secure random int in [minInclusive, maxInclusive].
Parameters: - minInclusive: The minimum value (inclusive). - maxInclusive: The maximum value (inclusive).
Returns:
- int: A random int in [minInclusive, maxInclusive].
- error: An error if crypto/rand fails.
func MustAnyInt ¶
func MustAnyInt() int
MustAnyInt returns a secure random int from the full range of int. It panics if an error occurs.
Returns:
- int: A random int in [-2147483647, 2147483648].
func MustAnyInt32 ¶
func MustAnyInt32() int32
MustAnyInt32 returns a random int32 in the full int32 range. It panics if an error occurs.
Returns:
- int32: A random int32 in [-2147483647, 2147483648].
func MustAnyInt64 ¶
func MustAnyInt64() int64
MustAnyInt64 returns a secure random int64 in the full int64 range. It panics if an error occurs.
Returns:
- int64: A random int64 in [-9223372036854775808, 9223372036854775807].
func MustBase64 ¶
Base64 returns a base64 encoded random string built from byteLen random bytes. It panics if an error occurs.
Parameters:
- byteLen: The length of the random bytes.
Returns:
- string: Base64 encoded random string.
func MustBool ¶
func MustBool() bool
Bool returns a secure random boolean. It panics if an error occurs.
Returns:
- bool
func MustChoice ¶
MustChoice returns a random choice from the provided arguments. It panics if an error occurs.
Parameters:
- choices: A slice of any type.
func MustDatetime ¶
Datetime returns a secure random time between year 1 and 9999. It panics if an error occurs.
Returns:
- time.Time: A random time between year 1 and 9999.
func MustEmail ¶
Email returns a random email address of totalLength characters. It panics on error.
Returns:
- string: A random email address.
func MustGetWithCustomCharset ¶
MustGetWithCustomCharset returns a random string of length characters drawn from the provided charset. It panics if an error occurs.
func MustHex ¶
MustHex returns a random hexadecimal string of length strLen. It panics if an error occurs.
Parameters:
- strLen: The length of the random hexadecimal string.
Returns:
- string: A random hexadecimal string of length strLen.
func MustInt32Range ¶
MustInt32Range returns a secure random int32 in [minInclusive, maxInclusive]. It panics if an error occurs.
Parameters: - minInclusive: The minimum value (inclusive). - maxInclusive: The maximum value (inclusive).
Returns:
- int32: A random int32 in [minInclusive, maxInclusive].
func MustInt64Range ¶
MustInt64Range returns a secure random int64 in [minInclusive, maxInclusive]. It panics if an error occurs.
Parameters: - minInclusive: The minimum value (inclusive). - maxInclusive: The maximum value (inclusive).
Returns:
- int64: A random int64 in [minInclusive, maxInclusive].
func MustIntRange ¶
MustIntRange returns a secure random int in [minInclusive, maxInclusive]. It panics if an error occurs.
Parameters: - minInclusive: The minimum value (inclusive). - maxInclusive: The maximum value (inclusive).
Returns:
- int: A random int in [minInclusive, maxInclusive].
func MustNegativeInt32 ¶
func MustNegativeInt32() int32
MustNegativeInt32 returns a secure random negative int32. It panics if an error occurs.
Returns:
- int32: A random int32 in [-2147483647, -1].
func MustNegativeInt64 ¶
func MustNegativeInt64() int64
MustNegativeInt64 returns a secure random negative int64. It panics if an error occurs.
Returns:
- int64: A random int64 in [-9223372036854775808, -1].
func MustPositiveInt32 ¶
func MustPositiveInt32() int32
MustPositiveInt32 returns a secure random positive int32. It panics if an error occurs.
Returns:
- int32: A random int32 in [1, 2147483648].
func MustPositiveInt64 ¶
func MustPositiveInt64() int64
MustPositiveInt64 returns a secure random positive int64. It panics if an error occurs.
Returns:
- int64: A random int64 in [1, 9223372036854775807].
func MustShuffle ¶
func MustShuffle(slice []any)
MustShuffle performs an in-place secure Fisher–Yates shuffle of the slice. It panics if an error occurs.
Parameters:
- slice: A slice of any type.
func MustSlicePickMany ¶
MustSlicePickMany returns a subset of items from the slice. It panics if an error occurs.
Parameters:
- slice: A slice of any type.
- chanceThreshold: An integer between 0 and 100.
Returns:
- []any: A slice of any type.
func MustSlicePickOne ¶
MustSlicePickOne returns one random element from the slice. It panics if an error occurs.
Parameters:
- slice: A slice of any type.
Returns:
- any: A random element from the slice.
func MustString ¶
MustString returns a secure random string of the given length using the default charset (lowerCaseAndNumbers). It panics if an error occurs.
Parameters:
- length: The length of the random string.
Returns:
- string: A random string of length characters drawn from the default
func MustStringSlice ¶
StringSlice returns a slice of random strings. It panics if an error occurs.
Parameters:
- sliceLength: The length of the slice.
- minStrLen: The minimum length of each string.
- maxStrLen: The maximum length of each string.
Returns:
- []string: A slice of random strings.
func MustTimeInNearFuture ¶
TimeInNearFuture returns a time a few minutes in the future. It panics if an error occurs.
Returns:
- time.Time: A time a few minutes in the future.
func MustTimeInNearPast ¶
TimeInNearPast returns a time a few minutes in the past. It panics if an error occurs.
Returns:
- time.Time: A time a few minutes in the past.
func NegativeInt32 ¶
NegativeInt32 returns a secure random negative int32.
Returns:
- int32: A random int32 in [-2147483647, -1].
- error: An error if crypto/rand fails.
func NegativeInt64 ¶
NegativeInt64 returns a secure random negative int64.
Returns:
- int64: A random int64 in [-9223372036854775808, -1].
- error: An error if crypto/rand fails.
func PositiveInt32 ¶
PositiveInt32 returns a secure random positive int32.
Returns:
- int32: A random int32 in [1, 2147483648].
- error: An error if crypto/rand fails.
func PositiveInt64 ¶
PositiveInt64 returns a secure random positive int64.
Returns:
- int64: A random int64 in [1, 9223372036854775807].
- error: An error if crypto/rand fails.
func Shuffle ¶
Shuffle performs an in-place secure Fisher–Yates shuffle of the slice.
Returns:
- error: An error if crypto/rand fails.
func SlicePickMany ¶
SlicePickMany returns a subset of items from the slice. For each item, a random chance is compared with chanceThreshold (0-100) to decide if it should be included.
Parameters:
- slice: A slice of any type.
- chanceThreshold: An integer between 0 and 100.
Returns:
- []any: A slice of any type.
- error: An error if crypto/rand fails.
func SlicePickOne ¶
SlicePickOne returns one random element from the slice. Returns an error if the slice is empty.
Returns:
- any: A random element from the slice.
- error: An error if the slice is empty or if crypto/rand fails.
func String ¶
String returns a secure random string of the given length using the default charset (lowerCaseAndNumbers).
Parameters:
- length: The length of the random string.
Returns:
- string: A random string of length characters drawn from the default charset.
- error: An error if crypto/rand fails.
func StringSlice ¶
StringSlice returns a slice of random strings. Each string length is randomly chosen between minStrLen and maxStrLen.
Parameters:
- sliceLength: The length of the slice.
- minStrLen: The minimum length of each string.
- maxStrLen: The maximum length of each string.
Returns:
- []string: A slice of random strings.
- error: An error if crypto/rand fails.
func TimeInNearFuture ¶
TimeInNearFuture returns a time a few minutes in the future.
Returns:
- time.Time: A time a few minutes in the future.
- error: An error if crypto/rand fails.
func TimeInNearPast ¶
TimeInNearPast returns a time a few minutes in the past.
Returns:
- time.Time: A time a few minutes in the past.
- error: An error if crypto/rand fails.
Types ¶
This section is empty.