aca

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 5 Imported by: 2

README

Adjective-colour-animal generator

Very simple library for generating random human-friendly identifiers. These are useful when the user may need to share the code with others, such as when inviting them to play a game.

The word lists are heavily based on those used by the unique-names-generator npm module, with some manual changes to exclude words that are hard to spell, hard to pronounce, or are biased or contentious in some way. To make up for the removals, a number of colours and fictional animals have been added.

Example identifiers:

beautiful-cerulean-timelord
inevitable-grey-toad
satisfied-yellow-tapir
weak-crimson-aardwolf
coherent-blush-guineafowl
poised-blue-vicuna
female-turquoise-dwarf

There are 1172 adjectives, 132 colours and 419 animals giving rise to just over 64 million unique combinations of words.

The longest adjective is 15 characters, colour is 11 characters, and animal is 13, giving rise to a maximum string length of 41 characters if using a single character delimiter like "-".

Example usage

package main

import (
	"github.com/csmith/aca"
	"math/rand"
	"time"
)

func main() {
	// Using the default generator
	generator, err := aca.NewDefaultGenerator()
	if err != nil {
		panic(err)
	}
	println(generator.Generate()) // prints something like "beautiful-cerulean-timelord"

	// Using a custom delimiter
	generator, err = aca.NewGenerator(", ", rand.NewSource(time.Now().UnixNano()))
	println(generator.Generate()) // prints something like "beautiful, cerulean, timelord"
}

Documentation

Overview

Example
gen, err := NewGenerator("-", rand.NewSource(time.Now().UnixNano()))
if err != nil {
	// Handle this better!
	panic(err)
}

for i := 0; i < 20; i++ {
	fmt.Println(gen.Generate())
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator provides methods to create adjective-colour-animal triplets.

func NewDefaultGenerator added in v1.1.0

func NewDefaultGenerator() (*Generator, error)

NewDefaultGenerator creates a new Generator using "-" as a delimiter and a default source of randomness.

func NewGenerator

func NewGenerator(delimiter string, source rand.Source) (*Generator, error)

NewGenerator creates a new Generator that will use the given delimiter and source of randomness.

func (*Generator) Generate

func (g *Generator) Generate() string

Generate creates a new {adjective, colour, animal} tuple and formats it using the configured delimiter.

Jump to

Keyboard shortcuts

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