gorando

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2019 License: MIT Imports: 7 Imported by: 2

README

gorando

Build Status Go Report Card MIT

A Golang package for dealing with randomness.

There are many packages like it, but this one is mine.

Examples

package main

import (
    "fmt"
    "github.com/cariad/gorando"
)

func main() {
    abc, _ := gorando.GetString("abc", 8)
    fmt.Println(abc)
    // bcbbcaab
}

The pool can include non-English characters, including emoji:

package main

import (
    "fmt"
    "github.com/cariad/gorando"
)

func main() {
    japanese, _ := gorando.GetString("こんにちは", 8)
    fmt.Println(japanese)
    // こにこちにんんは

    emoji, _ := gorando.GetString("🌈😎🐄", 8)
    fmt.Println(emoji)
    // 😎🐄😎🐄🐄🐄😎🌈
}

For quick access to common types of pool, there are LowerAlpha, UpperAlpha and Digits constants:

package main

import (
    "fmt"
    "github.com/cariad/gorando"
)

func main() {
    onlyLowerAlpha, _ := gorando.GetString(gorando.LowerAlpha, 8)
    fmt.Println(onlyLowerAlpha)
    // lnosdvql

    onlyAlpha, _ := gorando.GetString(gorando.LowerAlpha + gorando.UpperAlpha, 8)
    fmt.Println(onlyAlpha)
    // uvYJfgwU

    onlyAlphaNum, _ := gorando.GetString(gorando.LowerAlpha + gorando.UpperAlpha + gorando.Digits, 8)
    fmt.Println(onlyAlphaNum)
    // 4Pz453II
}

Functions

func GetRunes(pool string, count int) ([]rune, error)

GetRunes returns a slice of runes of length count populated by a random pick of runes out of the pool string.

func GetString(pool string, length int) (string, error)

GetString returns a string of length length populated by a random pick of runes out of the pool string.

Constants

LowerAlpha is a string containing all the characters in the English alphabet in lower-case form.

UpperAlpha is a string containing all the characters in the English alphabet in upper-case form.

Digits is a string containing all the base-10 digits.

Security

This package uses crypto/rand to avoid the predictability of math/random.

Also, this package intentionally does not log any pools or random selections.

Documentation

Index

Constants

View Source
const Digits = "0123456789"

Digits is a string containing all the base-10 digits.

View Source
const LowerAlpha = "abcdefghijklmnopqrstuvwxyz"

LowerAlpha is a string containing all the characters in the English alphabet in lower-case form.

View Source
const UpperAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

UpperAlpha is a string containing all the characters in the English alphabet in upper-case form.

Variables

This section is empty.

Functions

func GetRunes

func GetRunes(pool string, count int) ([]rune, error)

GetRunes returns a slice of runes selected randomly from the pool.

func GetString

func GetString(pool string, length int) (string, error)

GetString returns a random string constructed from runes in the pool.

Types

This section is empty.

Jump to

Keyboard shortcuts

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