Documentation ¶
Overview ¶
Package randutil provides various convenience functions for dealing with random numbers and strings.
Index ¶
- Constants
- Variables
- func AlphaString(n int) (string, error)
- func AlphaStringRange(min, max int) (string, error)
- func ChoiceInt(choices []int) (int, error)
- func ChoiceString(choices []string) (string, error)
- func IntRange(min, max int) (int, error)
- func String(n int, charset string) (string, error)
- func StringRange(min, max int, charset string) (string, error)
- type Choice
Constants ¶
const ( // Set of characters to use for generating random strings Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" Numerals = "1234567890" Alphanumeric = Alphabet + Numerals Ascii = Alphanumeric + "~!@#$%^&*()-_+={}[]\\|<,>.?/\"';:`" )
Variables ¶
var MinMaxError = errors.New("Min cannot be greater than max.")
Functions ¶
func AlphaString ¶
AlphaString returns a random alphanumeric string n characters long.
func AlphaStringRange ¶
AlphaRange returns a random alphanumeric string at least min and no more than max characters long.
func ChoiceString ¶
ChoiceString returns a random selection from an array of strings.
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 ¶
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.