randx

package
v0.0.0-...-75d2a66 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2015 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Set of characters to use for generating random strings
	Alphabet        = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
	LowAlphabet     = "abcdefghijklmnopqrstuvwxyz"
	Numerals        = "1234567890"
	Alphanumeric    = Alphabet + Numerals
	LowAlphanumeric = LowAlphabet + Numerals
	Ascii           = Alphanumeric + "~!@#$%^&*()-_+={}[]\\|<,>.?/\"';:`"
)

Variables

View Source
var MinMaxError = errors.New("Min cannot be greater than max.")

Functions

func AlphaString

func AlphaString(n int) (string, error)

AlphaString returns a random alphanumeric string n characters long.

func AlphaStringRange

func AlphaStringRange(min, max int) (string, error)

AlphaRange returns a random alphanumeric string at least min and no more than max characters long.

func ChoiceInt

func ChoiceInt(choices []int) (int, error)

ChoiceInt returns a random selection from an array of integers.

func ChoiceString

func ChoiceString(choices []string) (string, error)

ChoiceString returns a random selection from an array of strings.

func IntRange

func IntRange(min, max int) (int, error)

IntRange returns a random integer in the range from min to max.

func String

func String(n int, charset string) (string, error)

String returns a random string n characters long, composed of entities from charset.

func StringRange

func StringRange(min, max int, charset string) (string, error)

StringRange returns a random string at least min and no more than max characters long, composed of entitites from charset.

Types

type Choice

type Choice struct {
	Weight int
	Item   interface{}
}

A Choice contains a generic item and a weight controlling the frequency with which it will be selected.

func WeightedChoice

func WeightedChoice(choices []Choice) (Choice, error)

WeightedChoice used weighted random selection to return one of the supplied choices. Weights of 0 are never selected. All other weight values are relative. E.g. if you have two choices both weighted 3, they will be returned equally often; and each will be returned 3 times as often as a choice weighted 1.

Jump to

Keyboard shortcuts

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