namegen

package module
v0.0.0-...-472ac3f Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: Apache-2.0 Imports: 5 Imported by: 2

README

Name Generator

This is a name generator for fictional characters. It's first and foremost a library that can be added to other projects. It also has a namegen command line utility for generating names.

Building

Use the ./build.sh bash script to build the binary for your system.

Adding a new name generator

There are 4 steps to adding a new name generator to this project.

Note: There is a good guide to name formats here: https://www.fbiic.gov/public/2008/nov/Naming_practice_guide_UK_2006.pdf

Step one: add name lists as global variables

First, create a new .go file for your name lists. Within it, create three new global variables - one for male first names, one for female first names, and one for family names. They should be named appropriately (see existing files for reference).

Step two: add a new name generator to the map

In namegen.go, add your name generator to the map of name generators in the NameGeneratorFromType function. It should reference the global variables you created in step one.

Step three: add the name type to the CLI program's code

In cmd/namegen/main.go, add the name type to the nameLists array.

Step four: build and test your addition

Run ./build.sh and test out your new name generator.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorEmptyItems = errors.New("empty items")
)

Functions

func RandomItem

func RandomItem(items []string) (string, error)

RandomItem returns a random string from an array of strings

func RandomItemFromThresholdMap

func RandomItemFromThresholdMap(items map[string]int) string

RandomItemFromThresholdMap returns a random weighted string

func RandomItemInCollection

func RandomItemInCollection(item string, collection []string) bool

RandomItemInCollection checks to see if a string is in an array of strings

func RandomSeedFromString

func RandomSeedFromString(source string)

RandomSeedFromString uses a string to seed the random number generator

Types

type NameGenerator

type NameGenerator struct {
	MaleFirstNames   []string
	FemaleFirstNames []string
	LastNames        []string
}

NameGenerator is a set of names to use

func NameGeneratorFromType

func NameGeneratorFromType(origin, gender string) NameGenerator

NameGeneratorFromType sets up types of names

func (NameGenerator) CompleteName

func (gen NameGenerator) CompleteName(gender string) (string, error)

CompleteName returns a complete name

func (NameGenerator) FirstName

func (gen NameGenerator) FirstName(gender string) (string, error)

FirstName returns a first name

func (NameGenerator) LastName

func (gen NameGenerator) LastName() (string, error)

LastName returns a last name

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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