Skip to main content

A random name generator

Project description

NickNamer

NickNamer is a Python library for generating random names.

There are two options for random generation. The first is a random sequence of words that can be included with a defined format. The format is a string using tags for the available word types. A format string of "<noun>-<verb>" will return a string with a noun and a verb, separated by a dash. For example: 'car-run' or 'chair-talk'. Valid word type tags are: "<noun>", "<verb>", and "<adjective>".

The second option is a string of random letters (both capital and lower case) and digits. The length of the string is configurable. For a length of 8, some examples outputs are: 'mzSsqUOR', 'YkDXJF0E', 'zv52JbGH', 'czHoBnkJ'.

Installation

Install via pip:

pip install nicknamer

Usage

Below are example usages for the library. The docstrings for the individual classes may have more information.

Random word generation

To use the random word generation:

import nicknamer

# example format string
format_str="<noun>-<verb>-<adjective>"
word_generator = nicknamer.NickNamer(
    seed=12345,
    generator_class=nicknamer.WordNickNamer,
    format_str=format_str,
)
# print 3 example values
print(word_generator.get_value())
print(word_generator.get_value())
print(word_generator.get_value())

This will print:

Immortality-Sightsman-Aculeate
Stratifying-Touser-Vermifugal
Evangelistary-Upholsterer-Inductive

Changing the seed changes the values. The NickNamer class handles the random numbers, but you can also can also do that yourself and use WordNickNamer directly:

import random
import nicknamer

# example format string
format_str="<noun>-<verb>-<adjective>"
word_generator_alt = nicknamer.WordNickNamer(format_str=format_str)

rng = random.Random(12345)

# print 3 example values
print(word_generator_alt.get_value_from_generator(rng))
print(word_generator_alt.get_value_from_generator(rng))
print(word_generator_alt.get_value_from_generator(rng))

This gives the same results. get_value_from_generator() will accept any generator that implements a choice() function to select a value from a list. For example, a numpy random generator will work. Note that numpy must be installed separately.

import numpy
import nicknamer

# example format string
format_str="random verb: <verb>"
word_generator_alt = nicknamer.WordNickNamer(format_str=format_str)

rng = numpy.random.default_rng(12345)

# print example value
print(word_generator_alt.get_value_from_generator(rng))

Random alphanumeric generation

To use the random alphanumeric generation:

import nicknamer

alphanum_generator = nicknamer.NickNamer(
    seed=12345,
    generator_class=nicknamer.AlphaNumNickNamer,
    length=10,
)
# print 3 example values
print(alphanum_generator.get_value())
print(alphanum_generator.get_value())
print(alphanum_generator.get_value())

This will print:

zaZswmJkhA
IkIw7f8zFj
Slvbv78Ua6

This can also be used directly with an external random generator by creating the object nicknamer.AlphaNumNickNamer(length=10) and using get_value_from_generator(rng) as above.

License

apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nicknamer-0.0.3.tar.gz (319.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nicknamer-0.0.3-py3-none-any.whl (317.8 kB view details)

Uploaded Python 3

File details

Details for the file nicknamer-0.0.3.tar.gz.

File metadata

  • Download URL: nicknamer-0.0.3.tar.gz
  • Upload date:
  • Size: 319.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nicknamer-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ec5e4960626d64180120d0ae7633e4fb4d183234a52024960b16cdb843cd82fd
MD5 1b91f4521c8ef3c88c34ef920bdedb9b
BLAKE2b-256 1da95b4cef29eb64f21f47d8b30b35b9f21e6f89a19d1da5bdafc66b298c1ed0

See more details on using hashes here.

File details

Details for the file nicknamer-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: nicknamer-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 317.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nicknamer-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0fdfb8fead291f90a65fe595735e00804da6fec2deaf639ae2627b82b6b221dd
MD5 2a312a1d2b2f8f1dd49d9abdab181c27
BLAKE2b-256 5f2221aa5e0a5781fae2c7b4fa83d7200bd6c005ce1b684181f1ed55d13d1845

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page