Documentation ¶
Overview ¶
Package randchars quickly generates a chunk of random ASCII characters using a PRNG. Two different generators are provide: Generator and Base64.
Generator provides more flexibility in the set of characters used: a-zA-Z0-9, a-z0-9, A-Z0-9, a-zA-Z, a-z, A-Z, Base64, as defined in Table 1 of RFC 4648, and Base64URL, as defined in Table 2 of RFC 4648.
Base64 generates a chunk of Base 64 random characters. The character set used is from Table 1 of RFC 4648.
Calls to the package functions using the package global genarator are threadsafe.
Index ¶
- func Alpha(n int) []byte
- func AlphaNum(n int) []byte
- func Base64(n int) []byte
- func Base64Bytes(n int) []byte
- func Base64URL(n int) []byte
- func Base64URLBytes(n int) []byte
- func Int64() int64
- func LowerAlpha(n int) []byte
- func LowerAlphaNum(n int) []byte
- func ReSeed()
- func ReseedBase64()
- func ReseedBase64URL()
- func Seed(n int64)
- func SeedBase64(n int64)
- func SeedBase64URL(n int64)
- func SeedWithState(seed, state int64)
- func UpperAlpha(n int) []byte
- func UpperAlphaNum(n int) []byte
- type Base64Generator
- type Base64URLGenerator
- type Generator
- func (g *Generator) Alpha(n int) []byte
- func (g *Generator) AlphaNum(n int) []byte
- func (g *Generator) Base64(n int) []byte
- func (g *Generator) Base64URL(n int) []byte
- func (g *Generator) LowerAlpha(n int) []byte
- func (g *Generator) LowerAlphaNum(n int) []byte
- func (g *Generator) ReSeed()
- func (g *Generator) Seed(n int64)
- func (g *Generator) SeedWithState(seed, state int64)
- func (g *Generator) UpperAlpha(n int) []byte
- func (g *Generator) UpperAlphaNum(n int) []byte
- type Generatorer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Alpha ¶
Alpha returns a randomly generated []byte of length n using a-zA-Z. This will panic if n < 0.
func AlphaNum ¶
AlphaNum returns a randomly generated []byte of length n using a-zA-Z0-9. This will panic if n < 0.
func Base64 ¶
Base64 returns a randomly generated []byte of length n using base64, as defined in Table 1 of RFC 4648. This will panic if n < 0.
func Base64Bytes ¶
Base64Bytes returns n randomly generated Base 64 bytes.
func Base64URL ¶
Base64URL returns a randomly generated []byte of length n using base64url, as defined in Table 2 of RFC 4648 filename safe base64. This will panic if n < 0.
func Base64URLBytes ¶
Base64URLBytes returns n randomly generated Base64URL bytes.
func LowerAlpha ¶
LowerAlpha returns a randomly generated []byte of length n using a-z. This will panic if n < 0.
func LowerAlphaNum ¶
LowerAlphaNum returns a randomly generated []byte of length n using a-z0-9. This will panic if n < 0.
func ReseedBase64 ¶
func ReseedBase64()
ReseedBase64 seeds Base64Generator's prng using a value obtained from a CSPRNG.
func ReseedBase64URL ¶
func ReseedBase64URL()
ReseedBase64URL seeds Base64URLGenerator's prng using a value obtained from a CSPRNG.
func SeedBase64 ¶
func SeedBase64(n int64)
SeedBase64 seeds Base64Generator's prng using the provided value.
func SeedBase64URL ¶
func SeedBase64URL(n int64)
SeedBase64URL seeds Base64URLGenerator's prng using the provided value.
func SeedWithState ¶
func SeedWithState(seed, state int64)
SeedWithState seeds the Generator's prng and set's its state.
func UpperAlpha ¶
UpperAlpha returns a randomly generated []byte of length n using A-Z. This will panic if n < 0.
func UpperAlphaNum ¶
UpperAlphaNum returns a randomly generated []byte of length n using A-Z0-9. This will panic if n < 0.
Types ¶
type Base64Generator ¶
type Base64Generator struct {
// contains filtered or unexported fields
}
Base64 supports the Base 64 Alphabet as shown in Table 1 of RFC 4248. This uses an implementation of the XORoShiRo128+ PRNG: http://xoroshiro.di.unimi.it/.
This is more performant than using Generator for base64.
func NewBase64Generator ¶
func NewBase64Generator() *Base64Generator
NewBase64 returns an initialized Base64Generator that is ready to use. The seed value used is an int64 obtained from a CSPRNG.
func NewBase64GeneratorWithSeed ¶
func NewBase64GeneratorWithSeed(seed int64) *Base64Generator
NewBase64GeneratorWithSeed a Base64Generator using the received value as its seed.
func (*Base64Generator) Bytes ¶
func (g *Base64Generator) Bytes(n int) []byte
Bytes returns n randomly generated Base 64 bytes.
func (*Base64Generator) Reseed ¶
func (g *Base64Generator) Reseed()
Reseed seeds Base64Generator's prng using a value obtained from a CSPRNG.
func (*Base64Generator) Seed ¶
func (g *Base64Generator) Seed(n int64)
Seed seeds Base64Generator's prng using the provided value.
type Base64URLGenerator ¶
type Base64URLGenerator struct {
// contains filtered or unexported fields
}
Base64URL supports the Base64URL Alphabet as shown in Table 2 of RFC 4248. This uses an implementation of the XORoShiRo128+ PRNG: http://xoroshiro.di.unimi.it/.
This is more performant than using Generator for base64url.
func NewBase64URLGenerator ¶
func NewBase64URLGenerator() *Base64URLGenerator
NewBase64URL returns an initialized Base64GeneratorURL that is ready to use. The seed value used is an int64 obtained from a CSPRNG.
func NewBase64URLGeneratorWithSeed ¶
func NewBase64URLGeneratorWithSeed(seed int64) *Base64URLGenerator
NewBase64URLGeneratorWithSeed a Base64GeneratorURL using the received value as its seed.
func (*Base64URLGenerator) Bytes ¶
func (g *Base64URLGenerator) Bytes(n int) []byte
Bytes returns n randomly generated Base64URL bytes.
func (*Base64URLGenerator) Reseed ¶
func (g *Base64URLGenerator) Reseed()
Reseed seeds Base64URLGenerator's prng using a value obtained from a CSPRNG.
func (*Base64URLGenerator) Seed ¶
func (g *Base64URLGenerator) Seed(n int64)
Seed seeds Base64URLGenerator's prng using the provided value.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator generates the random ASCII characters. It relies on a PRNG that implements PCG: www.pcg-random.org.
func NewGeneratorSeedWithState ¶
NewGeneratorSeedWithState a Generator using the received values as its seed and state.
func NewGeneratorWithSeed ¶
NewGeneratorWithSeed a Generator using the received value as its seed.
func (*Generator) Alpha ¶
Alpha returns a randomly generated []byte of length n using a-zA-Z. This will panic if n < 0.
func (*Generator) AlphaNum ¶
AlphaNum returns a randomly generated []byte of length n using a-zA-Z0-9. This will panic if n < 0.
func (*Generator) Base64 ¶
Base64 returns a randomly generated []byte of length n using Base64, as defined in Table 1 of RFC 4648. This will panic if n < 0.
func (*Generator) Base64URL ¶
Base64URL returns a randomly generated []byte of length n using Base64URL, as defined in Table 2 of RFC 4648. This will panic if n < 0.
func (*Generator) LowerAlpha ¶
LowerAlpha returns a randomly generated []byte of length n using a-z. This will panic if n < 0.
func (*Generator) LowerAlphaNum ¶
LowerAlphaNum returns a randomly generated []byte of length n using a-z0-9. This will panic if n < 0.
func (*Generator) ReSeed ¶
func (g *Generator) ReSeed()
ReSeed seeds the Generator's prng using a value obtained from a CSPRNG.
func (*Generator) SeedWithState ¶
SeedWithState seeds the Generator's prng and set's its state.
func (*Generator) UpperAlpha ¶
UpperAlpha returns a randomly generated []byte of length n using A-Z. This will panic if n < 0.
func (*Generator) UpperAlphaNum ¶
UpperAlphaNum returns a randomly generated []byte of length n using A-Z0-9. This will panic if n < 0.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
randchars
randchars is a cli app that generates random characters.
|
randchars is a cli app that generates random characters. |
Package crandchars generates a chunk of random ASCII characters using a CSPRNG.
|
Package crandchars generates a chunk of random ASCII characters using a CSPRNG. |