str

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 Digits

func Digits(n int) string

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

func Intn

func Intn(max int) int

func Letters

func Letters(n int) string

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

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.

func String added in v1.3.4

func String(s string, n int) string

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

func Symbols

func Symbols(n int) string

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

Types

type Str

type Str struct{}
var StrHelper Str

func (Str) Log added in v1.3.4

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

Log 打印日志行

func (Str) LogError added in v1.3.4

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

LogError 打印错误

func (Str) LogSuccess added in v1.3.4

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

LogSuccess 打印成功

func (Str) New added in v1.3.4

func (Str) New() *Str

func (Str) PadLeftZeros added in v1.3.4

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

PadLeftZeros 前置补零

func (Str) Print added in v1.3.4

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

Print 按行打印

Jump to

Keyboard shortcuts

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