Giter VIP home page Giter VIP logo

golang-petname's Introduction

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"
        "math/rand"
        "time"
        "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 init() {
        rand.Seed(time.Now().UTC().UnixNano())
}

func main() {
        flag.Parse()
        rand.Seed(time.Now().UnixNano())
        fmt.Println(petname.Generate(*words, *separator))
}

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 <[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.

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

golang-petname's People

Contributors

dustinkirkland avatar mwhudson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

golang-petname's Issues

Publish docker image

Hi,
Nice tool!

Would you be open to publishing a simple Docker image on Docker Hub for this?

Petname generation is not "random" unless rand.Seed is set

This is fairly obvious after taking a peek at the source and seeing the use of rand.Intn. That said I think it would be a good idea to add a note in the Readme about this and recommend setting the seed before generating any petnames using the library. If this is the case and I'm not missing something I'd be happy to spin up a PR.

Thanks for the library!

Consider allow older versions of Go

For Incus (ex-LXD), we like supporting the past two major Go versions, that is, 1.20 and 1.21 currently.

Your recent change to introduce a go.mod came with you setting a minimal version of go 1.21.1 which is therefore breaking us.

I don't see any reason for petname to require 1.21.1, so you should be able to just go mod tidy --go=1.20 to set the base version to 1.20.

Filter out potentially offensive combinations

This may be interesting and funny, but I have just actually received holy-crappie from a call to petname.Generate(2, "-"). It happened when using random_pet Terraform resource and now I have AWS resources tagged with that interesting name.
It's not a problem in a test scenario, but I'd prefer to avoid such nasty surprises in production. What do you think about adding a filter for forbidden combinations to the code? I'm not sure how long the "naughty" list would be, but it might be interesting to think about other possible examples.

Randomness behaviour with go 1.20

You've got this function calling rand.Seed for a non deterministic mode.

func NonDeterministicMode() {

However, since go 1.20, rand is automatically seeded, unless explicitly disabled:

// Prior to Go 1.20, the generator was seeded like Seed(1) at program startup.
// To force the old behavior, call Seed(1) at program startup.
// Alternately, set GODEBUG=randautoseed=0 in the environment
// before making any calls to functions in this package.

Maybe you want to factor this behaviour in, not sure. For me personally, I called rand.Seed manually beforehand and simply had no change in behaviour. But for people expecting something deterministic, this might be confusing. Additionaly, this library might want to stop using globalrand and instead allow specifying a source, as this makes it easier to use within projects that use randomness for other purposes.

move init() from the shared package into the CLI

Hi,

We'd like to use your library to generate nonces but I'm concerned about the init() function that's included in petname.go. This init() will be called on startup and could conflict with other calls to rand.Seed().

In our case we have some code to alternate between a specific seed in order to repeat a test run and time.Now().UTC().UnixNano() for psuedo-random behavior.

Would you be open to simple PR to move the init() into https://github.com/dustinkirkland/golang-petname/blob/master/cmd/petname/main.go? This shouldn't affect the behavior of the petname utility but it will make it easier for us to reuse the library.

Thanks,
brian

Please tag releases

Please tag releases of this library that correspond to the versions you list in debian/changelog. Doing so will greatly help individuals who are packaging this library and using something like a watchfile to track new releases.

(I'm working on updating Debian's version of this package, and due to a historical decision about the versioning of Debian's packaging, Debian's version is a mashup of <version>+<git commit>. Proper tagging would eliminate this less than ideal situation.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.