rand

package module
v0.0.0-...-d037456 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2018 License: MIT Imports: 6 Imported by: 0

README

rand

A random library for Go.

Build Codecov ReportCard GoDoc License

Usage

$ go get -u -v github.com/LyricTian/rand
Import package
import "github.com/LyricTian/rand"
Generate a random string
rand.MustRandom(6, rand.Ldigit)
// 939430
Generate a short string
rand.MustShortStr([]byte("https://www.google.com"), 6, rand.Ldigit)
// [XZ1599 Xy8I3U KAHc2K NftD8p]
Random flag:
  • Ldigit
  • LlowerCase
  • LupperCase
  • LlowerAndUpperCase
  • LdigitAndLowerCase
  • LdigitAndUpperCase
  • LdigitAndLetter
Generate a random UUID
rand.MustUUID()
// a306e54f-672f-4011-889d-d09e98cbea89

MIT License

Copyright (c) 2018 Lyric

Documentation

Index

Constants

View Source
const (
	Ldigit = 1 << iota
	LlowerCase
	LupperCase
	LlowerAndUpperCase = LlowerCase | LupperCase
	LdigitAndLowerCase = Ldigit | LlowerCase
	LdigitAndUpperCase = Ldigit | LupperCase
	LdigitAndLetter    = Ldigit | LlowerCase | LupperCase
)

define a flag that generates a random string

Variables

View Source
var (
	ErrInvalidLength = errors.New("invalid random length")
	ErrInvalidFlag   = errors.New("invalid random flag")
)

definition error

Functions

func MustRandom

func MustRandom(length, flag int) string

MustRandom generate a random string specifying the length of the random number and the random flag (panic if an error occurs)

func MustShortStr

func MustShortStr(data []byte, length, flag int) []string

MustShortStr get a set of short strings of length (panic if an error occurs)

func MustUUID

func MustUUID() string

MustUUID generate a random UUID (panic if an error occurs)

func Random

func Random(length, flag int) (string, error)

Random generate a random string specifying the length of the random number and the random flag

func ShortStr

func ShortStr(data []byte, length, flag int) ([]string, error)

ShortStr get a set of short strings of length

func UUID

func UUID() (string, error)

UUID generate a random UUID, reference: https://github.com/google/uuid/blob/master/version4.go

Types

This section is empty.

Jump to

Keyboard shortcuts

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