random

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package random has helper functions to create random strings or bytes

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue. Taken from https://stackoverflow.com/questions/35781197/generating-a-random-fixed-length-byte-array-in-go

Types

type DefaultStringGenerator added in v0.24.0

type DefaultStringGenerator struct{}

DefaultStringGenerator generates random strings

func (DefaultStringGenerator) CryptoString added in v0.24.0

func (g DefaultStringGenerator) CryptoString(n int) (string, error)

CryptoString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue. This should be used when there are concerns about security and need something cryptographically secure.

type StringGenerator added in v0.24.0

type StringGenerator interface {
	CryptoString(n int) (string, error)
}

StringGenerator generates random strings

Directories

Path Synopsis
Package randomtest has test helpers for the random package
Package randomtest has test helpers for the random package

Jump to

Keyboard shortcuts

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