randstr

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: MIT Imports: 3 Imported by: 0

README

go-rand-str

random string generator for golang

example

s := randstr.Gen(10)
fmt.Print(s) // output: mUNERA9rI2


// Letters is source of generated random string.(Default: A~Z & a~z & 0~9)
randstr.SetSrcLetters([]rune("グレープフルーツ最高!!あとマンゴーも!!"))
s = randstr.Gen(6)
fmt.Print(s) // output: あ高ツフマレ

randstr.SetSrcLetters([]rune(randstr.LettersNumStr + randstr.LettersUpperStr))
s = randstr.Gen(8)
fmt.Print(s) // output: IIDAZG7H


// setting seed
randstr.GetRandModule().Seed(47)


// new RandStr
rs := randstr.New(
	rand.NewSource(2003),
	[]rune(randstr.LettersNumStr+"+-*/"),
)
s = rs.Gen(16)
fmt.Print(s) // output: 587466+2343008+8

Documentation

Index

Constants

View Source
const (
	// LettersNumStr is numbers from 0 to 9.
	LettersNumStr = "0123456789"
	// LettersUpperStr is upper case from A to Z.
	LettersUpperStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	// LettersLowerStr is lower case from a to z.
	LettersLowerStr = "abcdefghijklmnopqrstuvwxyz"
)

Variables

View Source
var (
	// ErrZeroLengthLetters is error.
	ErrZeroLengthLetters = errors.New("srcLetters must not be zero in length")
)

Functions

func Gen

func Gen(length uint) string

Gen generates random string.

func GetRandModule

func GetRandModule() *rand.Rand

GetRandModule gets randModule.

func GetSrcLetters

func GetSrcLetters() []rune

GetSrcLetters gets srcLetters.

func SetRandModule

func SetRandModule(newRandModule *rand.Rand)

SetRandModule sets randModule.

func SetSrcLetters

func SetSrcLetters(letters []rune) error

SetSrcLetters sets srcLetters.

Types

type RandStr

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

RandStr is random string generater.

func New

func New(src rand.Source, letters []rune) *RandStr

New returns new RandStr.

func (*RandStr) Gen

func (rs *RandStr) Gen(length uint) string

Gen generates random string.

func (*RandStr) GetRandModule

func (rs *RandStr) GetRandModule() *rand.Rand

GetRandModule gets randModule.

func (*RandStr) GetSrcLetters

func (rs *RandStr) GetSrcLetters() []rune

GetSrcLetters gets srcLetters.

func (*RandStr) SetRandModule

func (rs *RandStr) SetRandModule(newRandModule *rand.Rand)

SetRandModule sets randModule.

func (*RandStr) SetSrcLetters

func (rs *RandStr) SetSrcLetters(letters []rune) error

SetSrcLetters sets srcLetters.

Jump to

Keyboard shortcuts

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