| 1 | # petname |
| 2 | |
| 3 | ## Name |
| 4 | |
| 5 | **petname** − an [RFC1178](https://tools.ietf.org/html/rfc1178) implementation to generate pronounceable, sometimes even memorable, "pet names", consisting of a random combination of adverbs, an adjective, and an animal name |
| 6 | |
| 7 | ## Synopsis |
| 8 | |
| 9 | - Complete version: |
| 10 | ``` |
| 11 | usage: petname [-w|--words INT] [-l|--letters INT] [-s|--separator STR] [-d|--dir STR] [-c|--complexity INT] [-u|--ubuntu] |
| 12 | ``` |
| 13 | |
| 14 | - Python version: |
| 15 | ```bash |
| 16 | usage: petname [-h] [-w WORDS] [-l LETTERS] [-s SEPARATOR] |
| 17 | ``` |
| 18 | |
| 19 | ## Options |
| 20 | - `-w|--words` number of words in the name, default is 2, |
| 21 | - `-l|--letters` maximum number of letters in each word, default is unlimited, |
| 22 | - `-s|--separator` string used to separate name words, default is `'-'`, |
| 23 | - `-d|--dir` directory containing `adverbs.txt`, `adjectives.txt`, `names.txt`, default is `/usr/share/petname/`, |
| 24 | - `-c|--complexity` [0, 1, 2]; 0 = easy words, 1 = standard words, 2 = complex words, default=1, |
| 25 | - `-u|--ubuntu` generate ubuntu-style names, alliteration of first character of each word. |
| 26 | |
| 27 | ## Description |
| 28 | |
| 29 | 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. |
| 30 | |
| 31 | As such, PetName tries to follow the tenets of Zooko’s triangle. Names are: |
| 32 | |
| 33 | - human meaningful |
| 34 | - decentralized |
| 35 | - secure |
| 36 | |
| 37 | Besides this shell utility, there are also native libraries: [python-petname](https://pypi.org/project/petname/), [python3-petname](https://pypi.org/project/petname/), and [golang-petname](https://github.com/dustinkirkland/golang-petname). Here are some programmatic examples in code: |
| 38 | |
| 39 | ## Examples |
| 40 | |
| 41 | ```bash |
| 42 | $ petname |
| 43 | wiggly-yellowtail |
| 44 | |
| 45 | $ petname --words 1 |
| 46 | robin |
| 47 | |
| 48 | $ petname --words 3 |
| 49 | primly-lasting-toucan |
| 50 | |
| 51 | $ petname --words 4 |
| 52 | angrily-impatiently-sage-longhorn |
| 53 | |
| 54 | $ petname --separator ":" |
| 55 | cool:gobbler |
| 56 | |
| 57 | $ petname --separator "" --words 3 |
| 58 | comparablyheartylionfish |
| 59 | |
| 60 | $ petname --ubuntu |
| 61 | amazed-asp |
| 62 | |
| 63 | $ petname --complexity 0 |
| 64 | massive-colt |
| 65 | ``` |
| 66 | |
| 67 | ---- |
| 68 | |
| 69 | ## Code |
| 70 | |
| 71 | Besides this shell utility, there are also native libraries: python-petname, python3-petname, and golang-petname. Here are some programmatic examples in code: |
| 72 | |
| 73 | ### **Golang Example** |
| 74 | Install it with apt: |
| 75 | ```bash |
| 76 | $ sudo apt-get install golang-petname |
| 77 | ``` |
| 78 | |
| 79 | Or here's an example in golang code: |
| 80 | |
| 81 | ```golang |
| 82 | package main |
| 83 | |
| 84 | import ( |
| 85 | "flag" |
| 86 | "fmt" |
| 87 | "github.com/dustinkirkland/golang-petname" |
| 88 | ) |
| 89 | |
| 90 | var ( |
| 91 | words = flag.Int("words", 2, "The number of words in the pet name") |
| 92 | separator = flag.String("separator", "-", "The separator between words in the pet name") |
| 93 | ) |
| 94 | |
| 95 | func main() { |
| 96 | flag.Parse() |
| 97 | fmt.Println(petname.Generate(*words, *separator)) |
| 98 | } |
| 99 | ``` |
| 100 | |
| 101 | **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. |
| 102 | |
| 103 | ### **Python Example** |
| 104 | See: [on pypi](https://pypi.python.org/pypi/petname). |
| 105 | |
| 106 | Install it with [pip](https://pip.pypa.io/): |
| 107 | ```bash |
| 108 | $ [sudo] pip install petname |
| 109 | ``` |
| 110 | |
| 111 | ```python |
| 112 | #!/usr/bin/python |
| 113 | import argparse |
| 114 | import petname |
| 115 | import sys |
| 116 | |
| 117 | parser = argparse.ArgumentParser(description='Generate human readable random names') |
| 118 | parser.add_argument('-w', '--words', help='Number of words in name, default=2', default=2) |
| 119 | parser.add_argument('-l', '--letters', help='Maximum number of letters per word, default=6', default=6) |
| 120 | parser.add_argument('-s', '--separator', help='Separator between words, default="-"', default="-") |
| 121 | parser.options = parser.parse_args() |
| 122 | sys.stdout.write(petname.Generate(int(parser.options.words), parser.options.separator, int(parser.options.letters)) + "\n") |
| 123 | ``` |
| 124 | |
| 125 | ## Author |
| 126 | |
| 127 | This manpage and the utility were written by Dustin Kirkland <[email protected]> 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. |
| 128 | |
| 129 | The complete text of the Apache2 License can be found in `/usr/share/common-licenses/Apache-2.0` on Debian/Ubuntu systems. |