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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file randomwordgenerator-1.0.0.zip.
File metadata
- Download URL: randomwordgenerator-1.0.0.zip
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2d3a7cddcabc3aa7a27f544248e2a324eb836449cf5ed48a81204a13d26d905
|
|
| MD5 |
c232fc08e5ec9dcfdf4be9c165bd13a6
|
|
| BLAKE2b-256 |
0528b914e591374d70824b96c79315d311180966bb4f0568ab95cf3fa36ae3ac
|