Random string generation with upper case letters and digits

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

    Based on another Stack Overflow answer, Most lightweight way to create a random string and a random hexadecimal number, a better version than the accepted answer would be:

    ('%06x' % random.randrange(16**6)).upper()
    

    much faster.

提交回复
热议问题