grand

package
v2.4.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 5 Imported by: 154

Documentation

Overview

Package grand provides high performance random bytes/number/string generation functionality.

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 string which contains only digits, and its length is `n`.

func Intn

func Intn(max int) int

Intn returns an int number which is between 0 and max: [0, max).

Note that: 1. The `max` can only be greater than 0, or else it returns `max` directly; 2. The result is greater than or equal to 0, but less than `max`; 3. The result number is 32bit and less than math.MaxUint32.

func Letters

func Letters(n int) string

Letters returns a random string 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 string 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 Str

func Str(s string, n int) string

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

func Symbols

func Symbols(n int) string

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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