How to generate a unique order number

Source: Internet
Author: User
First, the order number has 3 properties: 1. Uniqueness  2. Not speculative 3. Efficiency

Uniqueness and unpredictability needless to say, efficiency is not a frequent database query to avoid duplication.
Moreover, the order number is short enough to meet these conditions.
I customized the order number in Java to generate the following way:
int r1= (int) (Math.random () * (10))//generating 2 0-9 random numbers
int r2= (int) (Math.random () * (10));
Long now = System.currenttimemillis ();//A 13-bit timestamp
String Paymentid =string.valueof (R1) +string.valueof (R2) +string.valueof (now);//Order ID

The current rule, two people in the same microsecond to submit orders repeat the probability of 1%
Order Effect: 251393292999921

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.