RandomWordGenerator
Python Library for Generating Random Words
Usage
from randomgenerator import randomwordgenerator num_words = 20 randomwordgenerator.generate_random_words(n = num_words)
Under the hood, the random word generator first tries to use the primary pathway.
primary
Word Source: FreeBSD Dictionary
def get_n_random_words(num_random_words, prefix = None, suffix = None, substr = None):
'''
@param prefix
- A character or phrase that all target words must start with
@param suffix
- A character or phrase that all target words must end with
@param substr
- A character or phrase that all target words must contain
@param num_random_words
- The number of random words to generate
- Must be nonnegative
@return
- a list of @num_random_words unique words from _URL that
meet the specified criteria
- all words meeting the specified criteria if @num_random_words
exceeds the number of matching words
- None if @num_random_words is < 0, [] if @num_random_words is 0
'''
If the primary generator fails (a.k.a, we lose Internet connectivity, so we can’t access the FreeBSD dictionary), the random word generator switches over to the backup pathway.
backup
def get_random_word(min_word_len, max_word_len):
'''
@param min_word_len
- Minimum number of characters that must be in random word
- Must be non-negative
@param max_word_len
- Maximum number of characters that can be in random word
- Must be non-negative
@return
- A random word whose length is >= @min_word_len and <= @max_word_len characters.
- If any of the inputs are invalid, then raise an InvalidWordLengthBoundsError.
'''
def get_n_random_words(n, word_len_bounds = (2, 10)):
'''
@param n
(Required)
Number of random words to generate
@param word_len_bounds
(Optional)
Tuple containing the bounds for the word length of each randomly generated word;
item 0 = minimum word length (2 by default), item 1 = maximum word length (10 by default)
@return
- A list with @n random words, where word_len_bounds[0] <= len(each word) <= word_len_bounds[1]
- An InvalidWordLengthBoundsError if word_len_bounds is an invalid tuple (length < 2)
'''
The key difference between the primary and backup pathways is that the latter might not generate actual words; it is actually creating various strings of varying lengths and characters. Overall, the backup pathway is not as ideal as the primary, but it is a suitable alternative in the event of a network failure.
Metadata
Release files for randomwordgenerator 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| randomwordgenerator-1.0.0.zip | 5.1 kB | Details |
Release files / randomwordgenerator-1.0.0.zip
| Download URL | randomwordgenerator-1.0.0.zip |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2d3a7cddcabc3aa7a27f544248e2a324eb836449cf5ed48a81204a13d26d905
|
|
BLAKE2b-256 checksum How to use checksums |
0528b914e591374d70824b96c79315d311180966bb4f0568ab95cf3fa36ae3ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |