python 3随机字生成器库

randomwordgenerator的Python项目详细描述


用于生成随机单词的python库

用法

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)
    '''

主路径和备份路径之间的关键区别在于 后者可能不会生成实际的单词;它实际上正在创建各种 不同长度和字符的字符串。总的来说,备份路径 虽然不如初选的理想,但它是 网络故障事件。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么我不能从ObjectInputStream读取ArrayList?   linux如何设置java时区?   java是一种拥有系统的方法。出来在循环中打印不同的内容?   scala Apache Spark:在Java中有效地使用mapPartitions   java Maven对com的依赖性。白天利用率   java将多个数据映射到单个id的表的正式名称是什么?   java如何在Android应用程序中隐藏FulterWave API键   SeleniumWebDriverJava:如何使用行号和列号单击表中的特定单元格   java Springbatch将数据从写入程序或处理器传递到RestConroller   java在Android TextView中一次换行两行,并带有跨距   java如何使这个rxjava zip并行运行?   JAVAutil。登录中。记录器不尊重java。util。登录中。数量   java无法将参数发布到服务器   java Eclipse:在自定义透视图/视图的状态行上显示作业进度   java在调用findAll()时,找到了多个具有给定标识符的行,但如果我使用findById()遍历所有条目,则可以工作;   Java中的正则表达式问题   Java中的实例变量   java如何在安卓中逐字搜索   java如何计算百分比