Random string generation with upper case letters and digits

前端 未结 30 3223
逝去的感伤
逝去的感伤 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:59

    I have gone though almost all of the answers but none of them looks easier. I would suggest you to try the passgen library which is generally used to create random passwords.

    You can generate random strings of your choice of length, punctuation, digits, letters and case.

    Here's the code for your case:

    from passgen import passgen
    string_length = int(input())
    random_string = passgen(length=string_length, punctuation=False, digits=True, letters=True, case='upper')
    

提交回复
热议问题