str

package
v2.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 5 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Letters      = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" // 52
	UpperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"                           // 26
	LowerLetters = "abcdefghijklmnopqrstuvwxyz"                           // 26
	Symbols      = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"                   // 32
	Digits       = "0123456789"                                           // 10

)

Functions

func B

func B(n int) []byte

B retrieves and returns random bytes of given length `n`.

func D

func D(min, max time.Duration) time.Duration

D returns a random time.Duration between min and max: [min, max].

func GetDigits added in v2.4.5

func GetDigits(n int) string

GetDigits returns a random str which contains only digits, and its length is `n`.

func GetLetters added in v2.4.5

func GetLetters(n int) string

GetLetters returns a random str which contains only letters, and its length is `n`.

func GetString added in v2.4.5

func GetString(s string, n int) string

GetString randomly picks and returns `n` count of chars from given str `s`. It also supports unicode str like Chinese/Russian/Japanese, etc.

func GetSymbols added in v2.4.5

func GetSymbols(n int) string

GetSymbols returns a random str which contains only symbols, and its length is `n`.

func Intn

func Intn(max int) int

func Meet

func Meet(num, total int) bool

Meet randomly calculate whether the given probability `num`/`total` is met.

func MeetProb

func MeetProb(prob float32) bool

MeetProb randomly calculate whether the given probability is met.

func N

func N(min, max int) int

N returns a random int between min and max: [min, max]. The `min` and `max` also support negative numbers.

func Perm

func Perm(n int) []int

Perm returns, as a slice of n int numbers, a pseudo-random permutation of the integers [0,n). TODO performance improving for large slice producing.

func S

func S(n int, symbols ...bool) string

S returns a random str which contains digits and letters, and its length is `n`. The optional parameter `symbols` specifies whether the result could contain symbols, which is false in default.

Types

type Str

type Str struct{}
var StrHelper Str

func (Str) Log

func (Str) Log(v ...any)

Log 打印日志行

func (Str) LogError

func (Str) LogError(v ...any)

LogError 打印错误

func (Str) LogSuccess

func (Str) LogSuccess(v ...any)

LogSuccess 打印成功

func (Str) New

func (Str) New() *Str

func (Str) PadLeftZeros

func (Str) PadLeftZeros(str string, length int) string

PadLeftZeros 前置补零

func (Str) Print

func (Str) Print(v ...any)

Print 按行打印

Jump to

Keyboard shortcuts

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