A good algorithm for generating an order number

前端 未结 10 1544
青春惊慌失措
青春惊慌失措 2021-01-31 06:27

As much as I like using GUIDs as the unique identifiers in my system, it is not very user-friendly for fields like an order number where a customer may have to repeat that to a

10条回答
  •  萌比男神i
    2021-01-31 07:16

    One solution would be to take the hash of some field of the order. This will not guarantee that it is unique from the order numbers of all of the other orders, but the likelihood of a collision is very low. I would imagine that without "doing a round trip to the database" it would be challenging to make sure that the order number is unique.

    In case you are not familiar with hash functions, the wikipedia page is pretty good.

提交回复
热议问题