A good algorithm for generating an order number

前端 未结 10 1447
青春惊慌失措
青春惊慌失措 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条回答
  •  清酒与你
    2021-01-31 07:02

    The straightforward answer to most of your bullet points:

    Make the first six digits a sequentially-increasing field, and append three digits of hash to the end. Or seven and two, or eight and one, depending on how many orders you envision having to support.

    However, you'll still have to call a function on the back-end to reserve a new order number; otherwise, it's impossible to guarantee a non-collision, since there are so few digits.

提交回复
热议问题