rand

package
v1.49.62 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Int

func Int() int

func Int32

func Int32() int32

func Int64

func Int64() int64

func SecretKey

func SecretKey() string

func ShortId

func ShortId() string

Returns short, url-friendly Id

func ShortPassword

func ShortPassword() string

Returns short, url-friendly Id

func String added in v1.49.26

func String(n int, alphabet string) string

String returns exactly n characters drawn uniformly from alphabet.

It is the primitive to reach for when the output has a shape someone will read back or type in — a referral code, a coupon — rather than base64 with the awkward characters filtered out afterwards. Filtering is what made referral codes "eight characters, unless the draw happened to contain four of '-' and '_', in which case seven or fewer".

Rejection sampling keeps the draw uniform. Folding a byte modulo the alphabet size would favour its first 256 % len(alphabet) characters, and a code with a lopsided alphabet is a code with less entropy than its length advertises.

Types

This section is empty.

Jump to

Keyboard shortcuts

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