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.2.tar.gz (319.5 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.2-py3-none-any.whl (317.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nicknamer-0.0.2.tar.gz
  • Upload date:
  • Size: 319.5 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.2.tar.gz
Algorithm Hash digest
SHA256 53069e9195db98596d435ecca44992d3f37c5f7f82eb9fc0abe8931b4db26cfd
MD5 467f8962d3101ebab58c341af54d59a2
BLAKE2b-256 4396b7d3d3009c6851a34bed1af9f9451a1f193203f7c140496d9a4fa9c30831

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nicknamer-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 317.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1a618cade27358204e35acfe1be58cf2d8d8c2aa27dfb968936eafbadb5b0d3c
MD5 a57ff4f0b87bea6703bf8f6d7a1abf65
BLAKE2b-256 c1aea87d47218f317930584e369a5f32f92c9133970f026fba55307d45955443

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