rand

package
v0.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package rand provides the random string

Index

Constants

This section is empty.

Variables

View Source
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)
)

predefined charsets for different random types

Functions

This section is empty.

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.

func (Kind) String

func (k Kind) String() string

type Rand

type Rand struct {
	// contains filtered or unexported fields
}

func CustomRand

func CustomRand(charset string) *Rand

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

func NewRand(rndType Kind) *Rand

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) RandBytes

func (r Rand) RandBytes(size int) []byte

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL