Random string generation with upper case letters and digits

前端 未结 30 3172
逝去的感伤
逝去的感伤 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 03:08

    import uuid
    lowercase_str = uuid.uuid4().hex  
    

    lowercase_str is a random value like 'cea8b32e00934aaea8c005a35d85a5c0'

    uppercase_str = lowercase_str.upper()
    

    uppercase_str is 'CEA8B32E00934AAEA8C005A35D85A5C0'

提交回复
热议问题