Help us shape the future of Go! Take the 2026 Go Developer Survey

random

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package random makes the random and derived strings the application hands out: verification codes, tokens and secrets from crypto/rand, and the invite-code encoding of user ids.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeBase62

func EncodeBase62(id int64) string

EncodeBase62 is the invite-code encoding: id in base 62 over the shuffled chars62 alphabet, most significant digit first, left-padded to six characters. The padding is chars62's last character next to the digits, then every third character before it. The padding makes the encoding irreversible and not injective (916132831 and 56800235583 both give "yyyyyy"); zero encodes as the single character "E" and a negative id as the padding alone. Invite codes are stored and shared, so the output must never change; TestEncodeBase62Golden pins it.

func Key

func Key(length int, keyType int) string

Key returns length random characters: letters and digits for keyType 1, digits otherwise, as in a verification code.

func KeyNew

func KeyNew(length int, keyType int) string

KeyNew is Key with one more keyType: 2 draws from upper-case letters and digits.

func StrToDashedString

func StrToDashedString(strNum string) string

StrToDashedString inserts a dash after every fourth character, to make a long code readable ("ABCD-EFGH-IJ").

Types

This section is empty.

Jump to

Keyboard shortcuts

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