Invitation code Generation Method

Source: Internet
Author: User
Tags generator

3. Primary key + Random code way, we generated a random code saved to the database will certainly have a primary key, with the primary key + random character combination. Production steps:

1 first get the ID from the ID generator, for example, 155.

2 fill in a fixed number of digits (such as 8-bit) of the string (not enough digits left to fill 0, more than the number of digits directly using the number), get: 00000155

3 randomly insert 1 letters or other non-numeric symbols after each number, and get: 0a0f0r0y0h1k5l5m

This allows you to get 1 random, unique invitation codes.

Advantages: Use is also relatively simple, do not query the database. The biggest advantage is that when querying, you can directly get the primary key ID according to the invitation code,

Then according to the ID to the database query (fast), and then compare the query out of the invitation code and the user submitted the invitation code is consistent.

Disadvantage: Need to use the ID generator, if the primary key is the database from the growth is not very good (need to insert the database to get ID, and then update the invitation code).

4. Sometimes the product manager says, I want the invitation code to be numeric. Why No why? I like it. * (&^ ^%&^$&^$ The Method 3 can be adapted to achieve the only pure digital random code.

1) Get id:155

2) Convert to 8:233

3) to string, and add ' 9 ' character in the back: 2339

4 randomly produces several random digit characters at the back: 2003967524987

When you move to 8, you don't get the 9 character and then add a ' 9 ' to the back so you can determine uniqueness. Finally, some random numbers will be generated behind.

Advantages and Disadvantages Same Method 3

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.