用法
from randomgenerator import randomwordgenerator
num_words = 20
randomwordgenerator.generate_random_words(n = num_words)
在引擎盖下,随机单词生成器首先尝试使用primary
通路。
初级
词源: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
'''
如果主生成器出现故障(也就是说,我们失去了互联网连接,所以
我们无法访问freebsd字典),随机单词生成器
切换到备用路径。
备份
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)
'''
主路径和备份路径之间的关键区别在于
后者可能不会生成实际的单词;它实际上正在创建各种
不同长度和字符的字符串。总的来说,备份路径
虽然不如初选的理想,但它是
网络故障事件。