当前位置: 首页>>代码示例>>Python>>正文


Python random.choice方法代码示例

本文整理汇总了Python中Crypto.Random.random.choice方法的典型用法代码示例。如果您正苦于以下问题:Python random.choice方法的具体用法?Python random.choice怎么用?Python random.choice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypto.Random.random的用法示例。


在下文中一共展示了random.choice方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: word_password

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import choice [as 别名]
def word_password(text, notice):
    """[length] - generates an easy to remember password with [length] (default 4) commonly used words"""
    try:
        length = int(text)
    except ValueError:
        length = 3

    if length > 10:
        notice("Maximum length is 50 characters.")
        return

    words = []
    # generate password
    for x in range(length):
        words.append(gen.choice(common_words))

    notice("Your password is '{}'. Feel free to remove the spaces when using it.".format(" ".join(words))) 
开发者ID:CloudBotIRC,项目名称:CloudBot,代码行数:19,代码来源:password.py

示例2: random_string

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import choice [as 别名]
def random_string(length=-1, charset=string.ascii_letters):
    """
    Returns a random string of "length" characters.
    If no length is specified, resulting string is in between 6 and 15 characters.
    A character set can be specified, defaulting to just alpha letters.
    """

    if length == -1:
        length = random.randrange(6, 16)
    rand_string = ''.join(random.choice(charset) for _ in range(length))
    return rand_string 
开发者ID:SySS-Research,项目名称:outis,代码行数:13,代码来源:strings.py

示例3: randomize_capitalization

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import choice [as 别名]
def randomize_capitalization(data):
    """
    Randomize the capitalization of a string.
    """

    return "".join(random.choice([k.upper(), k]) for k in data) 
开发者ID:SySS-Research,项目名称:outis,代码行数:8,代码来源:strings.py

示例4: randomString

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import choice [as 别名]
def randomString(length = -1, charset = string.ascii_letters):
    """
    Author: HarmJ0y, borrowed from Empire
    Returns a random string of "length" characters.
    If no length is specified, resulting string is in between 6 and 15 characters.
    A character set can be specified, defaulting to just alpha letters.
    """
    if length == -1: length = random.randrange(6,16)
    random_string = ''.join(random.choice(charset) for x in range(length))
    return random_string

#------------------------------------------------------------------------ 
开发者ID:Arno0x,项目名称:WSC2,代码行数:14,代码来源:helpers.py

示例5: generate_key

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import choice [as 别名]
def generate_key(self):
    # Function to generate a random key for encryption
    print("writing out key to " + os.getcwd())

    key = ''.join(random.choice('0123456789ABCDEF') for i in range(32))
    # DEV - Write to file
    fh = open("key.txt", "w")
    fh.write(key)
    fh.close()

    return key 
开发者ID:sithis993,项目名称:Crypter,代码行数:13,代码来源:Crypt.py

示例6: random_string

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import choice [as 别名]
def random_string(length=-1, charset=string.ascii_letters):
    """
    Returns a random string of "length" characters.
    If no length is specified, resulting string is in between 6 and 15 characters.
    A character set can be specified, defaulting to just alpha letters.
    """
    if length == -1:
        length = random.randrange(6, 16)
    random_string = ''.join(random.choice(charset) for x in range(length))
    return random_string 
开发者ID:EmpireProject,项目名称:EmPyre,代码行数:12,代码来源:helpers.py

示例7: randomize_capitalization

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import choice [as 别名]
def randomize_capitalization(data):
    """
    Randomize the capitalization of a string.
    """
    return "".join(random.choice([k.upper(), k]) for k in data) 
开发者ID:EmpireProject,项目名称:EmPyre,代码行数:7,代码来源:helpers.py

示例8: generate_password

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import choice [as 别名]
def generate_password(length=16, symbolgroups=DEFAULT_PASSWORD_SYMBOLS):
    """Generate a random password from the supplied symbol groups.
    At least one symbol from each group will be included. Unpredictable
    results if length is less than the number of symbol groups.
    Believed to be reasonably secure (with a reasonable password length!)
    """
    # NOTE(jerdfelt): Some password policies require at least one character
    # from each group of symbols, so start off with one random character
    # from each symbol group
    password = [random.choice(s) for s in symbolgroups]
    # If length < len(symbolgroups), the leading characters will only
    # be from the first length groups. Try our best to not be predictable
    # by shuffling and then truncating.
    random.shuffle(password)
    password = password[:length]
    length -= len(password)

    # then fill with random characters from all symbol groups
    symbols = ''.join(symbolgroups)
    password.extend([random.choice(symbols) for _i in range(length)])

    # finally shuffle to ensure first x characters aren't from a
    # predictable group
    random.shuffle(password)

    return ''.join(password) 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:28,代码来源:utils.py

示例9: password

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import choice [as 别名]
def password(text, notice):
    """[length [types]] - generates a password of <length> (default 10). [types] can include 'alpha', 'no caps',
    'numeric', 'symbols' or any combination: eg. 'numbers symbols'"""
    okay = []

    # find the length needed for the password
    numb = text.split(" ")

    try:
        length = int(numb[0])
    except ValueError:
        length = 12

    if length > 50:
        notice("Maximum length is 50 characters.")
        return

    # add alpha characters
    if "alpha" in text or "letter" in text:
        okay += list(string.ascii_lowercase)
        # adds capital characters if not told not to
        if "no caps" not in text:
            okay += list(string.ascii_uppercase)

    # add numbers
    if "numeric" in text or "number" in text:
        okay += list(string.digits)

    # add symbols
    if "symbol" in text or "special" in text:
        sym = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', '_', '+', '[', ']', '{', '}', '\\', '|', ';',
               ':', "'", '.', '>', ',', '<', '/', '?', '`', '~', '"']
        okay += sym

    # defaults to lowercase alpha + numbers password if the okay list is empty
    if not okay:
        okay = list(string.ascii_lowercase) + list(string.digits)

    # extra random lel
    random.shuffle(okay)
    chars = []

    for i in range(length):
        chars.append(random.choice(okay))

    notice("".join(chars)) 
开发者ID:CloudBotIRC,项目名称:CloudBot,代码行数:48,代码来源:password.py


注:本文中的Crypto.Random.random.choice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。