How can we leave a number that is equal to a random number.

Source: Internet
Author: User
An APP requires that a globally unique number be generated (similar to a QQ number), but leave a good number in advance or determine whether the number to be obtained is a good number when the user registers... How can this be done? For example, start with 8 bits, such as 88888888,12345678, 11111111,222222, 3333... an APP requires that a globally unique number be generated (similar to a QQ number), but leave a good number in advance or determine whether the number to be obtained is a good number when the user registers...

How can this be done?

For example, starting from 8 bits, such as 88888888,12345678, 11111111,222222, 33333333,20.001, cannot be provided to users ......

Reply content:

An APP requires that a globally unique number be generated (similar to a QQ number), but leave a good number in advance or determine whether the number to be obtained is a good number when the user registers...

How can this be done?

For example, starting from 8 bits, such as 88888888,12345678, 11111111,222222, 33333333,20.001, cannot be provided to users ......

The real question of the landlord is: how to determine whether a number is "good", rather than knowing how to screen a pile of good numbers (that's not easy yet ?).

This problem is common. I believe that both QQ and telecom operators have experienced the same problem. It is feasible to set some rules in a simple way, but it is certainly incomplete and will inevitably miss some.

The most important thing is not only to distinguish which data is beautiful, but also to determine its "Beauty level ".

The solution I can provide is to develop a crawler to obtain the domain name, QQ number, mobile phone number related to this number, whether the mobile phone number has been registered, the registration time, and the price. For example, www.12345678.com must be very expensive, right?

After the data is crawled, a "indicator" is given for sorting. The so-called indicator can be the price, and the top number is the "good number. If you are interested in the research, you can summarize a series of rules based on this ranking, such as "number of digits" and "number of repeated numbers", and then use these rules as input, "indicators" are used as the output, and the weight of each rule is calculated using the mechanical learning method. If you can organize a powerful neural network, you can directly use the entire number as the input.

But someone has certainly studied this problem, right? So before doing this job-first look for the paper!

Regular Expression filtering is supported.
For example, (\ d) \ 1 {2,} indicates that the same number appears three or more times in a row. (\ D) \ 1 \ 2 indicates the situation of ABAB.
Of course, regular expressions still have limitations, such as the inability to easily search for shunzi. In this case, you need to use the generator to generate such special numbers into a regular expression. For example, the following expression (123 | 234 | 345 | 456 | 567 | 678 | 789 |) can be generated by splicing to match the three-digit increment.

  1. Design Regular Expression for numbers that are not intended for users. You can also consider maintaining the number blacklist.
  2. Random randomly generates a number and checks whether it exists in the blacklist or in the database. If it exists, call the generate function again.
  3. The generated number is stored in the database.

In fact, it is a "Courier" phone string, which is as self-triggered as an iPod. It cannot be a "Courier" phone string, such as "ABC" or "ABCABC.

As long as a method is used to determine whether to "not like hosts", it will be automatically regenerated as long as it is enough.

According to your description, the strings "unlike hosts" should include:

  • Number of unique records, such as 88888888

  • For example, 12345678

  • Integer, such as 10000000

  • Text number, such as 10000001

The token generation is as follows:

function isPseudo(str) {    str = str + "";    return isDuplicate(str) || isSeries(str) || isIdealInteger(str) || isPalindromic(str);}function isDuplicate(str) {    var first = str[0];    for (var i = 1, n = str.length; i < n; ++i) {        if (str[i] !== first)            return false;    }    return true;}function isSeries(str) {    var series1 = 1 * str[0],        series2 = 1 * str[0];    for (var i = 1, n = str.length; i < n; ++i) {        var j = 1 * str[i];        if (j !== ++series1 && j !== --series2)            return false;    }    return true;}function isIdealInteger(str) {    for (var i = 1, n = str.length; i < n; ++i) {        if (str[i] !== "0")            return false;    }    return true;}function isPalindromic(str) {    for (var i = 0, n = str.length, n2 = n/2; i < n2; ++i) {        if (str[i] !== str[n - 1 - i])            return false;    }    return true;}

Then I found several data records. The results are as follows:

Object {8888: true, 10000: true, 100001: true, 1112111: true, 12345678: true, 342333423: false, 657865789: false}

In the last generation, data is not as powerful as hosts (that is, beautiful). In addition, the permission for a single number is also important, after adding permissions, you can get the "watermark" degree of data.

I didn't want to write so many replies, but I felt a little confused...

The core of this issue is divided into two subproblems:
1. What kind of number is a good number?
2. How can I assign these numbers separately?

For question 1, it is basically impossible to be completely intelligent. People's knowledge is needed, so it must be you.ExamplesAll the rules are followed by matching the numbers that meet the rules. For example, ABAB, ABBB, AABB, and AAAA may contain 8 or 6 numbers.
When writing code in this way, we will implement a bunch of interfaces of boolean isAwesomeNumber (String number), and then match them one by one, just like the templete mode.

For question 2, it depends on your business logic. If you are selling mobile phone numbers, you need to select them for classification in advance, and enter a number segment, execute the above method to determine whether any rule of the number is satisfied. The output result achieves the expected function.

  1. First, you need to develop a "relatively smooth number" standard.
  2. Before each generation, determine whether the criteria are met. If it is satisfied, we will push it back and judge again ...... Until a common number is found.
  3. The question is "generate a random number ". If we want to be completely random and globally unique, We need to judge the weight of the random result. For example, we need to find the minimum number that is greater than this number and has no weight ". It seems that the performance is slightly worse than that of the server.
  4. The question is "APP requirement". I feel that it is best to generate this number on the server, instead of the APP.

Generate randomly and filter the generated and to be left.JavaImplementation:

RandomStringUtils.randomNumeric(8)

Used:commons-lang3

I am more interested in your problem. I plan to write a class library. Leave a hole in it first. After the writing is complete, the address and usage will be attached. So let me first talk about my ideas:

A good or bad condition is determined by a machine. Therefore, if it is a pure good/bad bool value, I don't think it makes much sense, because this is just a filter, I have two ideas:

  1. Check whether the numeric string is of a certain type, such as 123 = ABC, 456 = AABB.
  2. Process the given numeric string and obtain its law, such as ABC, AAA, and AABB.
  3. Process the given numeric string, and finally give an integer output to indicate its degree of good or bad

For example, 3 also involves a single number. For example, 8 should have a slightly larger weight.

Write several rules first,
Then traverse from 0,
Rule-compliant whitelist
Non-conforming

For more information, see the following two answers:
1. For the definition of a good number, just as policybi says, "What kind of number is a good number 』
2. How to filter (generate a number)

For question 1. In my opinion, you can directly refer to the existing rules (the Rules are for the end number of the mobile phone number). After all, the quality of the number is the feeling of people.
In addition, you do not need to set too many rules. There are nine rules in the link to ensure that the most "Shun" number is allocated separately, at the same time, the user may obtain relatively "good" numbers outside the rules. For example, the user can obtain numbers such as ABAC at random upon application.

For question 2.
For common users
Step 1: generate a random number.
Step 2: Check whether the generated number is a "good" number.
Step 3: If the number is good, return to the first step, not to the fourth step.
Step 4: Return (after returning, You need to determine whether the number is used)

// Assume that low-level users can use ABC (123,234,345,...) and advanced users can use ABCDE (12345, 23456 ,...)
For paying users
Step 1: view the level
Step 2: generate one or more random numbers based on the level (for example, low level) (for example, if 2 is generated, ABC is 234)
Step 3 (optional): Check that this digit does not comply with the rules of advanced users. The result is returned to step 2 and does not conform to the rules of advanced users.
Step 4: Return (after returning, You need to determine whether the number is used)

I wrote a demo to check whether the generated number is a good number. The implementation of other languages is similar.

# required para:num,type list of intdef is_charm_num(num):    def is_AAAA(num):        return num[-4] == num[-3] \                and num[-4] == num[-2]\                and num[-4] == num[-1]    def is_ABCDE(num):        return num[-5] + 1 == num[-4] \                and num[-5] + 2 == num[-3] \                and num[-5] + 3 == num[-2] \                and num[-5] + 4 == num[-1]    def is_ABABAB(num):        return num[-6] == num[-4] \                and num[-6] == num[-2] \                and num[-5] == num[-3] \                and num[-5] == num[-1]    return is_AAAA(num) or is_ABABAB(num) or is_ABCDE(num)    if __name__ == '__main__':        num = 12345678        num_list = []        #num_list = map(int,str(num))        for n in str(num):            num_list.append(int(n))        is_charm_num(num_list)

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.