Random string generation with upper case letters and digits

前端 未结 30 3180
逝去的感伤
逝去的感伤 2020-11-22 02:51

I want to generate a string of size N.

It should be made up of numbers and uppercase English letters such as:

  • 6U1S75
  • 4Z4UKK
  • U911K4
30条回答
  •  感情败类
    2020-11-22 02:58

    A simple one:

    import string
    import random
    character = string.lowercase + string.uppercase + string.digits + string.punctuation
    char_len = len(character)
    # you can specify your password length here
    pass_len = random.randint(10,20)
    password = ''
    for x in range(pass_len):
        password = password + character[random.randint(0,char_len-1)]
    print password
    

提交回复
热议问题