randutil

package
v0.54.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 5 Imported by: 34

Documentation

Overview

Package randutil provides methods to generate random strings and salts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ASCII

func ASCII(length int) (string, error)

ASCII returns a securely generated random ASCII string. It reads random numbers from crypto/rand and searches for printable characters. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller must not continue.

func Alphabet added in v0.8.1

func Alphabet(length int) (string, error)

Alphabet returns a random string of the given length using the 52 alphabetic characters in the POSIX/C locale (a-z+A-Z).

func Alphanumeric

func Alphanumeric(length int) (string, error)

Alphanumeric returns a random string of the given length using the 62 alphanumeric characters in the POSIX/C locale (a-z+A-Z+0-9).

func Bytes added in v0.15.2

func Bytes(size int) ([]byte, error)

Bytes generates a new byte slice of the given size.

func Hex

func Hex(length int) (string, error)

Hex returns a random string of the given length using the hexadecimal characters in lower case (0-9+a-f).

func Salt

func Salt(size int) ([]byte, error)

Salt generates a new random salt of the given size.

func String

func String(length int, chars string) (string, error)

String returns a random string of a given length using the characters in the given string. It splits the string on runes to support UTF-8 characters.

func UUIDv4 added in v0.8.3

func UUIDv4() (string, error)

UUIDv4 returns the string representation of a UUID version 4. Because 6 bits are used to indicate the version 4 and the variant 10, the randomly generated part has 122 bits.

Types

This section is empty.

Jump to

Keyboard shortcuts

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