Documentation ¶
Overview ¶
Package rand provides the random string
Index ¶
Constants ¶
const DefaultSaltSize = 16
DefaultSaltSize is the default length of the salt string.
Variables ¶
var ( Digit = NewRand(KindDigit) LowerCase = NewRand(KindLowerCase) UpperCase = NewRand(KindUpperCase) Symbol = NewRand(KindSymbol) LowerAndUpperCase = NewRand(KindLowerCase | KindUpperCase) DigitAndLowerCase = NewRand(KindDigit | KindLowerCase) DigitAndUpperCase = NewRand(KindDigit | KindUpperCase) All = NewRand(KindAll) )
Functions ¶
func GenerateRandom ¶ added in v0.0.18
GenerateRandom generates a random salt string of specified length.
Parameters:
length int - the desired length of the salt string
Return value:
string - the generated random salt string
func GenerateSalt ¶ added in v0.0.18
func GenerateSalt() string
GenerateSalt generates a random salt string of specified length.
Return value:
string - the generated random salt string
Types ¶
type Kind ¶
type Kind int
const ( KindDigit Kind = 1 << iota KindLowerCase Kind = 1 << iota KindUpperCase Kind = 1 << iota KindSymbol Kind = 1 << iota KindAll Kind = KindDigit | KindLowerCase | KindUpperCase | KindSymbol KindCustom Kind = 0xFF )
Define a series of character type constants representing different categories of characters. KindDigit - Represents digit characters. KindLowerCase - Represents lowercase letter characters. KindUpperCase - Represents uppercase letter characters. KindSymbol - Represents symbol characters. KindAll - Represents the collective set of all character types, including digits, lowercase, uppercase, and symbols.
type Rand ¶
type Rand struct {
// contains filtered or unexported fields
}
func CustomRand ¶
CustomRand creates a new Rand object with a custom charset.
Parameters: - charset: a string representing the custom charset.
Return: - a pointer to a Rand object.
func NewRand ¶
NewRand generates a new Rand object based on the given random type.
Parameters: - rndType: an integer representing the random type.
Return: - a pointer to a Rand object.
func (*Rand) Close ¶ added in v0.0.36
func (r *Rand) Close()
Close releases the resources associated with the Rand object.
func (*Rand) RandBytes ¶
RandBytes generates a random byte slice of given size using the given charset.
Parameters: - size: the length of the byte slice to be generated.
Return: - []byte: the generated random byte slice.
func (*Rand) RandString ¶ added in v0.0.36
RandString generates a random string of given size using the given charset.
Parameters: - size: the length of the string to be generated.
Return: - string: the generated random string.
func (*Rand) Read ¶ added in v0.0.18
The Read method populates the given byte slice by randomly selecting characters.
Parameters: p []byte: The byte slice to be populated.
Return values: n int: The number of bytes actually populated. err error: An error encountered during population, always nil in this implementation.