當前位置: 首頁>>代碼示例>>Python>>正文


Python random.shuffle方法代碼示例

本文整理匯總了Python中Crypto.Random.random.shuffle方法的典型用法代碼示例。如果您正苦於以下問題:Python random.shuffle方法的具體用法?Python random.shuffle怎麽用?Python random.shuffle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Crypto.Random.random的用法示例。


在下文中一共展示了random.shuffle方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: parse_args

# 需要導入模塊: from Crypto.Random import random [as 別名]
# 或者: from Crypto.Random.random import shuffle [as 別名]
def parse_args():
    import argparse
    import itertools
    import sys

    parser = argparse.ArgumentParser(description='Fragment an HTTP request over multiple MPTCP flows.  '
                                                 'Requires root privileges for scapy.')
    parser.add_argument("--ip", action="store", dest="src_ip", help="use the specified source IP for all traffic")
    parser.add_argument('target', action="store", help=' Target IP')
    parser.add_argument('-p', '--port', action="store", type=int, help='target port', default=80)
    parser.add_argument("-n", '--nsubflows', action="store", type=int, help='Number of subflows to create', default=5)
    parser.add_argument('--first_src_port', action="store", type=int, help='First of nsubflows src ports', default=1001)
    parser.add_argument('--path', action="store", help='Path to request', default="/neodemopayload")
    parser.add_argument('--file', action="store", help='File to send instead of a payload', default=None)
    parser.add_argument('--shuffle', action="store", help='Shuffle the port order', default=False)
    parser.add_argument('--random_src_ports', action="store", help='use random ports', default=False)

    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)

    args = parser.parse_args()
    args.src_ip = args.src_ip if args.src_ip else get_local_ip_address(args.target)
    return args.target, args.port, args.src_ip, args.nsubflows, args.path, args.first_src_port, args.file, args.shuffle, args.random_src_ports 
開發者ID:Neohapsis,項目名稱:mptcp-abuse,代碼行數:26,代碼來源:mptcp_fragmenter.py

示例2: generate_password

# 需要導入模塊: from Crypto.Random import random [as 別名]
# 或者: from Crypto.Random.random import shuffle [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

示例3: password

# 需要導入模塊: from Crypto.Random import random [as 別名]
# 或者: from Crypto.Random.random import shuffle [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.shuffle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。