Random string generation with upper case letters and digits

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

    I would like to suggest you next option:

    import crypt
    n = 10
    crypt.crypt("any sring").replace('/', '').replace('.', '').upper()[-n:-1]
    

    Paranoic mode:

    import uuid
    import crypt
    n = 10
    crypt.crypt(str(uuid.uuid4())).replace('/', '').replace('.', '').upper()[-n:-1]
    

提交回复
热议问题