Creating a unique alphanumeric 10-character string

前端 未结 7 2185
青春惊慌失措
青春惊慌失措 2020-12-06 12:32

I\'m looking to create a simple short-lived reservation system, and I\'d like to generate confirmation numbers that are

  • unique
  • random-looking
7条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 12:58

    You can use whatever, even a plain random number generator; however, you should check that the reservation code isn't already present. If this is the case, add characters ('x') to the string (date+user) until you get a new random/sha1/etc.

    I'm only looking to have ~500 reservations, so I don't imagine high likelyhood of collissions.

    Another stupid idea: generate 1000 or 2000 unique random numbers with the desired properties, store them somewhere, and assign them to the users as they register :)

提交回复
热议问题