codename

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: MIT Imports: 5 Imported by: 28

README

Codename

Go Report Card     PkgGoDev

an RFC1178 implementation to generate pronounceable, sometimes even memorable, "superhero like" codenames, consisting of a random combination of adjective and noun.

Usage

Codename it's a package, so all you need to do is import it into your code:

package main

import (
	"fmt"
	"github.com/lucasepe/codename"
)

func main() {
	rng, err := codename.DefaultRNG()
	if err != nil {
		panic(err)
	}

	for i := 0; i < 8; i++ {
		name := codename.Generate(rng, 0)
		fmt.Println(name)
	}
}

This is how the output looks like (since it's random your will be different).

absolute-karatecha
moving-colleen
game-nova
fine-madrox
pro-penguin
keen-morbius
firm-iron
refined-epoch

You can request the addition of a token to create even more entropy:

package main

import (
	"fmt"
	"github.com/lucasepe/codename"
)

func main() {
	rng, err := codename.DefaultRNG()
	if err != nil {
		panic(err)
	}

	for i := 0; i < 8; i++ {
		name := codename.Generate(rng, 4)
		fmt.Println(name)
	}
}

note the token (with the specified length) added at the end:

hopeful-toad-men-133b
blessed-man-thing-2bdc
unique-starfox-4271
full-butterfly-2470
accepted-santa-claus-e24e
merry-belphegor-65da
willing-medusa-cdf4
adapting-nightstar-f626

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRNG

func DefaultRNG() (*rand.Rand, error)

DefaultRNG returns a new pseudo-random source seeded by a crypto level seed.

func Generate

func Generate(rng *rand.Rand, tokenLength int) string

Generate generates and returns a random hero name. Eventually you can specify a `tokenLength` greater then zero to generate and additional token and create even more entropy.

func NewCryptoSeed

func NewCryptoSeed() (int64, error)

NewCryptoSeed returns a crypto level random numbers generator seed. It returns an error and a seed equals to -1 if the underlying system call fails.

Types

This section is empty.

Jump to

Keyboard shortcuts

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