petname

package module
v0.0.0-...-fdd95a3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 2 Imported by: 312 modules, 299 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

petname

Name

petname − an RFC1178 implementation to generate pronounceable, sometimes even memorable, "pet names", consisting of a random combination of adverbs, an adjective, and an animal name

Synopsis

  • Complete version:
usage: petname [-w|--words INT] [-l|--letters INT] [-s|--separator STR] [-d|--dir STR] [-c|--complexity INT] [-u|--ubuntu]
  • Python version:
usage: petname [-h] [-w WORDS] [-l LETTERS] [-s SEPARATOR]

Options

  • -w|--words number of words in the name, default is 2,
  • -l|--letters maximum number of letters in each word, default is unlimited,
  • -s|--separator string used to separate name words, default is '-',
  • -d|--dir directory containing adverbs.txt, adjectives.txt, names.txt, default is /usr/share/petname/,
  • -c|--complexity [0, 1, 2]; 0 = easy words, 1 = standard words, 2 = complex words, default=1,
  • -u|--ubuntu generate ubuntu-style names, alliteration of first character of each word.

Description

This utility will generate "pet names", consisting of a random combination of an adverb, adjective, and an animal name. These are useful for unique hostnames or container names, for instance.

As such, PetName tries to follow the tenets of Zooko’s triangle. Names are:

  • human meaningful
  • decentralized
  • secure

Besides this shell utility, there are also native libraries: python-petname, python3-petname, and golang-petname. Here are some programmatic examples in code:

Examples

$ petname
wiggly-yellowtail

$ petname --words 1
robin

$ petname --words 3
primly-lasting-toucan

$ petname --words 4
angrily-impatiently-sage-longhorn

$ petname --separator ":"
cool:gobbler

$ petname --separator "" --words 3
comparablyheartylionfish

$ petname --ubuntu
amazed-asp

$ petname --complexity 0
massive-colt

Code

Besides this shell utility, there are also native libraries: python-petname, python3-petname, and golang-petname. Here are some programmatic examples in code:

Golang Example

Install it with apt:

$ sudo apt-get install golang-petname

Or here's an example in golang code:

package main

import (
        "flag"
        "fmt"
        "github.com/dustinkirkland/golang-petname"
)

var (
        words = flag.Int("words", 2, "The number of words in the pet name")
        separator = flag.String("separator", "-", "The separator between words in the pet name")
)

func main() {
        flag.Parse()
        fmt.Println(petname.Generate(*words, *separator))
}

Note: As of Go 1.20+, the random number generator is automatically seeded at program startup, so no manual seeding is required. Petname generation will be random by default.

Python Example

See: on pypi.

Install it with pip:

$ [sudo] pip install petname
#!/usr/bin/python
import argparse
import petname
import sys

parser = argparse.ArgumentParser(description='Generate human readable random names')
parser.add_argument('-w', '--words', help='Number of words in name, default=2', default=2)
parser.add_argument('-l', '--letters', help='Maximum number of letters per word, default=6', default=6)
parser.add_argument('-s', '--separator', help='Separator between words, default="-"', default="-")
parser.options = parser.parse_args()
sys.stdout.write(petname.Generate(int(parser.options.words), parser.options.separator, int(parser.options.letters)) + "\n")

Author

This manpage and the utility were written by Dustin Kirkland <dustin.kirkland@gmail.com> for Ubuntu systems (but may be used by others). Permission is granted to copy, distribute and/or modify this document and the utility under the terms of the Apache2 License.

The complete text of the Apache2 License can be found in /usr/share/common-licenses/Apache-2.0 on Debian/Ubuntu systems.

Documentation

Overview

Package petname is a library for generating human-readable, random names for objects (e.g. hostnames, containers, blobs).

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adjective

func Adjective() string

Adjective returns a random adjective from a list of petname adjectives. It uses the global random source (automatically seeded in Go 1.20+).

func Adverb

func Adverb() string

Adverb returns a random adverb from a list of petname adverbs. It uses the global random source (automatically seeded in Go 1.20+).

func Generate

func Generate(words int, separator string) string

Generate generates and returns a random pet name. It takes two parameters: the number of words in the name, and a separator token. If a single word is requested, simply a Name() is returned. If two words are requested, an Adjective() and a Name() are returned. If three or more words are requested, a variable number of Adverb()s, an Adjective(), and a Name() are returned. The separator can be any character, string, or the empty string. It uses the global random source (automatically seeded in Go 1.20+), which is already safe for concurrent use.

For deterministic use, create a Generator with New() instead — give each goroutine its own Generator if you need concurrent deterministic generation.

Example

Example of using the traditional package-level functions (backward compatible)

// Old API - still works exactly as before
// Uses global rand (auto-seeded in Go 1.20+)
name := petname.Generate(2, "-")
fmt.Println(name)

func Name

func Name() string

Name returns a random name from a list of petname names. It uses the global random source (automatically seeded in Go 1.20+).

func NonDeterministicMode deprecated

func NonDeterministicMode()

NonDeterministicMode seeds the random number generator with the current time.

Deprecated: As of Go 1.20, the global random generator is automatically seeded at program startup, making this function unnecessary. It is maintained for backward compatibility but has no effect when using Go 1.20+. See: https://go.dev/doc/go1.20#math/rand

Types

type Generator

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

Generator generates random petnames using a specific random source. This allows for deterministic generation (e.g., for testing).

A Generator is not safe for concurrent use by multiple goroutines: its *rand.Rand is unsynchronized. For concurrent generation, create a separate Generator (each with its own rand.Rand) per goroutine — see ExampleNew_concurrent.

func New

func New(rnd *rand.Rand) *Generator

New creates a new Generator with the specified random source. If rnd is nil, the global math/rand functions are used (same as package-level functions), which are safe for concurrent use. For deterministic generation, pass rand.New(rand.NewSource(seed)).

Example (Concurrent)

Example of using the new Generator API for concurrent use.

A single Generator is NOT safe for concurrent use — give each goroutine its own Generator (and its own rand.Rand), as done here.

gen1 := petname.New(rand.New(rand.NewSource(1)))
gen2 := petname.New(rand.New(rand.NewSource(2)))

// Each generator is only ever used by the goroutine that owns it.
name1 := gen1.Generate(2, "-")
name2 := gen2.Generate(2, "-")

fmt.Println(name1)
fmt.Println(name2)
Output:
desired-lynx
settled-wolf
Example (Deterministic)

Example of using the new Generator API with deterministic seed

// New API - deterministic generation for testing
gen := petname.New(rand.New(rand.NewSource(42)))

// Generate predictable names
fmt.Println(gen.Generate(2, "-"))
fmt.Println(gen.Generate(2, "-"))
fmt.Println(gen.Generate(2, "-"))
Output:
sought-mudfish
accurate-badger
full-racer

func (*Generator) Adjective

func (g *Generator) Adjective() string

Adjective returns a random adjective from the generator's random source.

Example

Example of generating individual words with deterministic behavior

gen := petname.New(rand.New(rand.NewSource(100)))

fmt.Println(gen.Adjective())
fmt.Println(gen.Adverb())
fmt.Println(gen.Name())
Output:
real
apparently
buzzard

func (*Generator) Adverb

func (g *Generator) Adverb() string

Adverb returns a random adverb from the generator's random source.

func (*Generator) Generate

func (g *Generator) Generate(words int, separator string) string

Generate generates a random pet name with the specified number of words and separator. If a single word is requested, simply a Name() is returned. If two words are requested, an Adjective() and a Name() are returned. If three or more words are requested, a variable number of Adverb()s, an Adjective(), and a Name() are returned. The separator can be any character, string, or the empty string.

func (*Generator) Name

func (g *Generator) Name() string

Name returns a random name from the generator's random source.

Directories

Path Synopsis
cmd
petname command

Jump to

Keyboard shortcuts

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