randz

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CHAR_SET       = "ABCDEFGHJKMNPQRSTUVWXYZ23456789"
	CHAR_LOWER_SET = "abcdefghjkmnpqrstuvwxyz23456789"
)

Variables

View Source
var ErrInvalidBase32 = errors.New("invalid base32")

Functions

func SetIdGeneratorStartTime

func SetIdGeneratorStartTime(t time.Time)

SetIdGeneratorStartTime set the start time of the default id generator

func SetStrGeneratorCharSet added in v0.0.15

func SetStrGeneratorCharSet(charSet string)

func String

func String(n int) string

String returns a random string with the specified length.

Types

type CountGenerator

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

CountGenerator is a generator for count

func (*CountGenerator) AddRule

func (r *CountGenerator) AddRule(period, periodEndMaxIncr, interval, intervalMaxIncr int)

AddRule add count increase rule

func (*CountGenerator) Generate

func (r *CountGenerator) Generate(id string, diff int) int

Generate generate count

func (*CountGenerator) Max

func (r *CountGenerator) Max(diff int) int

Max return max count

func (*CountGenerator) Min

func (r *CountGenerator) Min(diff int) int

Min return min count

type ID

type ID int64

ID is alias of int64

func Id

func Id() ID

Id return a random id

func ParseBase32

func ParseBase32(b []byte) (ID, error)

ParseBase32 parse the base32 string to id

func (ID) Base2

func (f ID) Base2() string

Base2 return the base2 string of id

func (ID) Base32

func (f ID) Base32() string

Base32 return the base32 string of id

func (ID) Base36

func (f ID) Base36() string

Base36 return the base36 string of id

func (ID) Int64

func (f ID) Int64() int64

Int64 return int64

func (ID) String

func (f ID) String() string

String return the string of id

type IdGenerator

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

IdGenerator is a id generator

func NewIdGenerator

func NewIdGenerator(startTime time.Time, randBit int) IdGenerator

NewIdGenerator | 1 bit Unused | 41bit timestamp | 2~22bit rand |

func (*IdGenerator) Generate

func (r *IdGenerator) Generate() ID

Generate generate a id

type LockRandSource added in v0.0.15

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

func NewLockRandSource added in v0.0.15

func NewLockRandSource(seed int64) *LockRandSource

func (*LockRandSource) Int63 added in v0.0.15

func (r *LockRandSource) Int63() int64

func (*LockRandSource) Seed added in v0.0.15

func (r *LockRandSource) Seed(seed int64)

type StrGenerator

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

StrGenerator is a random string generator.

func NewStrGenerator

func NewStrGenerator(charSet string, randSource rand.Source) StrGenerator

NewStrGenerator returns a new StrGenerator.

func (*StrGenerator) Generate

func (r *StrGenerator) Generate(n int) string

Generate returns a random string with the specified length.

Jump to

Keyboard shortcuts

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