randomutil

package
v0.0.0-...-50f2563 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: MIT Imports: 4 Imported by: 0

README

randomutil

Library containing various random helpers

Get a random integer

number := randomutil.Rand(0, 20)

Get a random float

number := randomutil.Rand(-10.0, 10.0)

Get a random string

str = randomutil.String(20, randomutil.AsciiLetters)

Get a random choice

sequence := []string{"abc", "def", "ghi", "jkl"}
item := randomutil.Choice(sequence)

Get multi random choices

sequence := []string{"abc", "def", "ghi", "jkl"}
subsequence := randomutil.Choices(sequence, 2)

Shuffle

sequence := []string{"abc", "def", "ghi", "jkl"}
sequence = randomutil.Shuffle(sequence)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AsciiLowercase        []rune
	AsciiUppercase        []rune
	AsciiLetters          []rune
	Digits                []rune
	AsciiLettersAndDigits []rune
	Punctuation           []rune
	Printable             []rune
)

Functions

func Choice

func Choice[T any](sequence []T) T

Return a random element from the non-empty sequence

func Choices

func Choices[T any](population []T, k int) []T

Return a k sized list of elements chosen from the population with replacement.

func Rand

func Rand[T constraints.Integer | constraints.Float](start, stop T) T

Random a number in range [start, stop)

func Shuffle

func Shuffle[T any](sequence []T) []T

Shuffle the sequence in place.

func String

func String(n int, vocab []rune) string

Generate a random string with length n from set of vocaburary

Types

This section is empty.

Jump to

Keyboard shortcuts

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