random

package
v0.41.8 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWorkerID 无效的 workerID,取值范围 [0, maxWorkerID]
	ErrWorkerID = errors.New("bad worker id")
	// ErrTimeBackward 时间倒退,当前时间比上一次记录的时间还要小
	ErrTimeBackward = errors.New("time backward")
)

Functions

func Int

func Int(min, max int64) int64

Int 获取指定范围内的整数

func NewUUID

func NewUUID() string

NewUUID 全局唯一标识符,12byte 基于时间戳,主机信息,进程 ID 生成,每次调用值加 1,具有原子性 eg: NewUUID() -> 5cb840f90a5dcd71e779ba64 eg: NewUUID() -> 5cb840f90a5dcd71e779ba65

func String

func String(length int) string

String 获取指定长度的字符串

func Uint32

func Uint32() uint32

Uint32 获取随机数,类型为 uint32

Types

type Snowflake added in v0.41.8

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

Snowflake 用来生成 uuid 的工具

func NewSnowflake added in v0.41.8

func NewSnowflake(workerID uint32) (*Snowflake, error)

NewSnowflake ..

func (*Snowflake) UUID added in v0.41.8

func (snowflake *Snowflake) UUID() (uint64, error)

UUID 获取 uuid

Jump to

Keyboard shortcuts

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