[go: up one dir, main page]

CN1874357A - Method for generating id symbol - Google Patents

Method for generating id symbol Download PDF

Info

Publication number
CN1874357A
CN1874357A CN 200510112526 CN200510112526A CN1874357A CN 1874357 A CN1874357 A CN 1874357A CN 200510112526 CN200510112526 CN 200510112526 CN 200510112526 A CN200510112526 A CN 200510112526A CN 1874357 A CN1874357 A CN 1874357A
Authority
CN
China
Prior art keywords
value
range
ids
generating
generated
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN 200510112526
Other languages
Chinese (zh)
Other versions
CN100579133C (en
Inventor
李阳林
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN200510112526A priority Critical patent/CN100579133C/en
Publication of CN1874357A publication Critical patent/CN1874357A/en
Application granted granted Critical
Publication of CN100579133C publication Critical patent/CN100579133C/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种产生ID的方法,包括以下步骤:A.配置ID的取值范围,根据ID的可用性划分ID的取值区间;B.在所划分的任意一个取值区间中任取一个ID作为新产生的ID。利用本发明,能够产生满足全部数字、唯一、随机和长度可配置要求的ID,大大提高了产生满足全部数字、唯一、随机和长度可配置要求ID的效率,并能够满足大数据量业务应用的要求。The invention discloses a method for generating an ID, which comprises the following steps: A. configuring the value range of the ID, and dividing the value range of the ID according to the availability of the ID; B. randomly selecting one of the divided value ranges ID as the newly generated ID. Utilizing the present invention can generate IDs that meet the requirements of all numbers, uniqueness, randomness, and configurable length, greatly improves the efficiency of generating IDs that meet the requirements of all numbers, uniqueness, randomness, and configurable lengths, and can meet the needs of large-scale business applications Require.

Description

一种产生标识符的方法A way to generate an identifier

技术领域technical field

本发明涉及通信领域的标识符产生技术,特别涉及一种产生标识符的方法。The invention relates to an identifier generation technology in the communication field, in particular to a method for generating an identifier.

背景技术Background technique

在通信技术领域中,标识符(ID)的应用非常广泛。例如电话卡、充值卡或银行卡等各种卡的卡号都是一个ID,用于唯一标识一张卡;电话会议接入码、网络会议接入码等也都是一个ID,用于唯一标识一个电话会议或网络会议。上述各种ID应满足以下要求:In the field of communication technology, identifiers (IDs) are widely used. For example, the card number of various cards such as telephone cards, recharge cards, or bank cards is an ID, which is used to uniquely identify a card; the access code of a conference call, the access code of a web conference, etc. are also an ID, used to uniquely identify a card. Conference call or web conference. The various IDs mentioned above should meet the following requirements:

1、ID为数字的组合,使用户能够在通信终端上输入。1. The ID is a combination of numbers, so that the user can input it on the communication terminal.

2、ID具有唯一性,一个ID只能标识一个对象,不能与已有的ID重复。2. The ID is unique. An ID can only identify one object and cannot be duplicated with an existing ID.

3、ID具有随机性,每次产生的ID没有任何规律,任何人任何时候都不能通过已知的ID,推导出新产生的ID。3. The ID is random, and the ID generated each time has no rules. No one can deduce the newly generated ID from the known ID at any time.

4、ID具有长度可配置性,用户可根据被标识对象数量的变化来配置ID的长度。4. The length of the ID is configurable, and the user can configure the length of the ID according to the change of the number of marked objects.

现有技术中,一般利用以下两种方式来产生满足上述要求的ID:一种是利用每位随机并组合的方式;另一种是利用系统当前时间戳与随机数组合的方式。In the prior art, the following two methods are generally used to generate IDs meeting the above requirements: one is to use random combination of each bit; the other is to use the combination of the current timestamp of the system and a random number.

其中,利用每位随机并组合的方式产生ID的原理如下:如果要产生一个N位的ID,则对于N位中每一位分别产生[0,9]之间的随机数,将产生的随机数组合在一起形成一个N位的ID,然后判断已有的ID中是否包含有新产生的这个ID,如果有,则说明新产生的ID与已有的ID重复,需要再次产生一个ID,直至新产生的ID与已有的ID不重复为止。Among them, the principle of generating an ID by random combination of each bit is as follows: If an N-bit ID is to be generated, a random number between [0, 9] is generated for each of the N bits, and the generated random number The arrays are combined to form an N-bit ID, and then it is judged whether the existing ID contains the newly generated ID. If so, it means that the newly generated ID is duplicated with the existing ID, and an ID needs to be generated again until The newly generated ID does not duplicate the existing ID.

利用系统当前时间戳与随机数组合的方式产生ID的原理如下:计算机编程语言可以提供获取系统当前时间戳的方法及产生随机数的随机函数,利用计算机编程语言提供的获取系统当前时间戳的方法获取系统的当前时间戳,利用计算机编程语言提供的产生随机数的随机函数产生一个一位或几位的随机数,然后将获取的时间戳设置在高位,将产生的随机数设置在低位,二者组合在一起形成一个ID。The principle of using the combination of the system's current time stamp and random number to generate an ID is as follows: the computer programming language can provide a method for obtaining the system's current time stamp and a random function for generating random numbers, and use the method provided by the computer programming language to obtain the system's current time stamp Obtain the current time stamp of the system, use the random function provided by the computer programming language to generate a random number of one or several digits, then set the obtained time stamp at the high position, and set the generated random number at the low position. or combined to form an ID.

这里,利用计算机编程语言提供的获取系统当前时间戳的方法所获取的系统当前时间戳,一般是从1970年1月1日0时0分0秒起到现在某一时刻所经过的秒数,该秒数在计算机中一般用4字节的整型数来存储。Here, the current time stamp of the system obtained by using the method of obtaining the current time stamp of the system provided by the computer programming language is generally the number of seconds elapsed from 0:00:00 on January 1, 1970 to a certain moment now, The number of seconds is generally stored in a computer as a 4-byte integer.

对于第一种产生ID的方式而言,虽然产生的ID满足全部数字、唯一、随机和长度可配置的要求,但是已有ID的数量越多,已有ID中包含有新产生的ID的概率就越大,对于新产生的ID包含在已有ID的情况,又要重新生成ID,……,如此反复,产生ID的效率很低,无法满足一些对产生ID的效率要求高的场合。For the first method of generating IDs, although the generated IDs meet the requirements of all numbers, uniqueness, randomness, and configurable length, the more existing IDs there are, the probability that the existing IDs contain the newly generated ID The bigger it is, for the situation that the newly generated ID is included in the existing ID, the ID must be regenerated, ..., and so on, the efficiency of generating the ID is very low, and some occasions that require high efficiency of generating the ID cannot be satisfied.

对于第二种产生ID的方式而言,由于在现有的计算机系统中,时间戳一般使用四字节的整型数来表示,其长度已达到10个字符,如果在其后再加上一个一位或几位的随机数,将导致产生ID的位数过长,不能很好地满足用户根据被标识对象数量的变化来配置ID长度的要求。另外,由于利用随机函数产生的随机数是可能发生重复的,如果每秒钟允许产生多个ID,则产生的ID就可能发生重复,这样仍需要同第一种产生ID的方式一样,判断新产生的ID是否重复,所以第二种产生ID的方式限制了每秒钟只能产生一个ID,显然无法满足大数据量业务应用的要求。For the second way of generating ID, since in the existing computer system, the time stamp is generally represented by a four-byte integer, and its length has reached 10 characters. If you add a A random number of one or several digits will result in an excessively long number of digits in the generated ID, which cannot well meet the user's requirement to configure the length of the ID according to the change in the number of identified objects. In addition, because the random number generated by the random function may be repeated, if multiple IDs are allowed to be generated per second, the generated ID may be repeated, so it is still necessary to judge the new ID in the same way as the first method of generating the ID. Whether the generated ID is repeated, so the second method of generating ID is limited to only one ID per second, which obviously cannot meet the requirements of large data volume business applications.

发明内容Contents of the invention

有鉴于此,本发明的主要目的在于提供一种产生ID的方法,以提高产生满足全部数字、唯一、随机和长度可配置要求ID的效率,并满足大数据量业务应用的要求。In view of this, the main purpose of the present invention is to provide a method for generating IDs to improve the efficiency of generating IDs that meet the requirements of all numbers, uniqueness, randomness, and configurable length, and meet the requirements of large-volume business applications.

为达到上述目的,本发明提供了一种产生ID的方法,包括以下步骤:To achieve the above object, the present invention provides a method for generating ID, comprising the following steps:

A、配置ID的取值范围,根据ID的可用性划分ID的取值区间;A. Configure the value range of the ID, and divide the value range of the ID according to the availability of the ID;

B、在所划分的任意一个取值区间中任取一个ID作为新产生的ID。B. Randomly select an ID from any of the divided value intervals as a newly generated ID.

上述方案中,步骤A中所述的根据ID的可用性划分ID的取值区间为:在配置的ID的取值范围中根据所有已用的ID确定当前所有可用的ID,将当前所有可用的ID划分为ID值连续的至少一个取值区间。In the above solution, the division of the ID value interval according to the availability of the ID described in step A is as follows: in the value range of the configured ID, all currently available IDs are determined according to all used IDs, and all currently available IDs are divided into Divided into at least one value interval with continuous ID values.

上述方案中,所述的步骤B包括:In the above-mentioned scheme, described step B comprises:

B1、对所划分的所有取值区间进行编号;B1. Numbering all the divided value intervals;

B2、利用随机函数产生编号数目范围内的一个随机数,选择编号与产生的随机数相同的取值区间,判断所选择用于产生ID的取值区间内ID的个数,如果该取值区间内只有一个ID,则取该ID作为新产生的ID;如果该取值区间内有一个以上的ID,则执行步骤B3;B2. Utilize the random function to generate a random number within the range of the number of numbers, select the same value interval of the number and the generated random number, and judge the number of IDs in the value interval selected for generating the ID, if the value interval If there is only one ID in the value range, then take this ID as the newly generated ID; if there is more than one ID in the value range, then perform step B3;

B3、利用随机函数产生该取值区间中ID数目范围内的一个随机数,取该取值区间中与该随机数对应的ID作为新产生的ID。B3. Using a random function to generate a random number within the range of the number of IDs in the range of values, and taking the ID corresponding to the random number in the range of values as a newly generated ID.

上述方案中,所述ID需产生多个,该方法进一步包括:根据ID的可用性更新ID的取值区间,在更新后的任意一个取值区间中任取一个ID作为新产生的ID。In the above solution, multiple IDs need to be generated, and the method further includes: updating the value interval of the ID according to the availability of the ID, and randomly selecting an ID in any updated value interval as the newly generated ID.

上述方案中,所述产生上一个ID时选择用于产生ID的取值区间内只有一个ID;所述更新ID的取值区间为:删除该取值区间,并对剩余的取值区间重新编号。In the above solution, there is only one ID in the value interval selected for generating the ID when the last ID is generated; the value interval of the update ID is: delete the value interval, and renumber the remaining value intervals .

上述方案中,所述产生上一个ID时选择用于产生ID的取值区间内有一个以上的ID,且将该取值区间的一个边界ID作为新产生的ID;所述更新ID的取值区间为:删除该取值区间中作为新产生ID的边界ID,更新该取值区间。In the above scheme, when the last ID is generated, there is more than one ID in the value interval selected for generating the ID, and a boundary ID of the value interval is used as a newly generated ID; the value of the update ID The interval is: delete the boundary ID as the newly generated ID in the value interval, and update the value interval.

上述方案中,所述产生上一个ID时选择用于产生ID的取值区间内有一个以上的ID,且将该取值区间的一个非边界ID作为新产生的ID;所述更新ID的取值区间为:删除该取值区间中作为新产生ID的非边界ID,将该取值区间划分为两个取值区间,并对所有取值区间重新编号。In the above scheme, when the last ID is generated, there is more than one ID in the value range selected for generating the ID, and a non-boundary ID of the value range is used as a newly generated ID; the value of the updated ID is The value range is as follows: delete the non-boundary ID as the newly generated ID in the value range, divide the value range into two value ranges, and renumber all the value ranges.

因此,本发明提供的这种产生ID的方法,通过配置ID的取值范围,根据ID的可用性划分ID的取值区间,并利用随机函数在所划分的任意一个取值区间中任取一个ID作为新产生的ID,能够产生满足全部数字、唯一、随机和长度可配置要求的ID。Therefore, the method for generating an ID provided by the present invention divides the value interval of the ID according to the usability of the ID by configuring the value range of the ID, and uses a random function to randomly select an ID in any of the divided value intervals. As a newly generated ID, it is possible to generate an ID that meets the requirements of all numbers, uniqueness, randomness, and configurable length.

利用本发明,由于ID的取值范围可以由用户根据实际需要来配置,设定ID的最大值和最小值,所以能够保证产生的ID为全部数字且长度可配置的ID。在需要产生多个ID时,由于每次产生ID后都要更新ID的取值区间,使每次都在未用ID的范围内产生ID,所以能够保证产生ID的唯一性。由于本发明是利用随机函数来随机选择产生ID的取值区间,并在该取值区间中利用随机函数来随机选择一个ID作为产生的ID,所以能够在最大程度上保证产生ID的随机性。因此,本发明能够产生满足全部数字、唯一、随机和长度可配置要求的ID。With the present invention, since the value range of the ID can be configured by the user according to actual needs, and the maximum and minimum values of the ID can be set, it can be ensured that the generated ID is an ID with all numbers and a configurable length. When multiple IDs need to be generated, the value range of the ID must be updated after each generation of the ID, so that the ID is generated within the range of unused IDs each time, so the uniqueness of the generated ID can be guaranteed. Since the present invention uses a random function to randomly select a value interval for generating an ID, and uses a random function to randomly select an ID as the generated ID in the value interval, the randomness of ID generation can be guaranteed to the greatest extent. Thus, the present invention is capable of generating IDs that meet all the requirements of being numeric, unique, random, and configurable in length.

由于每次都在未用ID的范围内产生ID,保证产生的ID满足唯一性要求,在产生ID时不必判断产生的ID是否会发生重复,所以大大提高了产生满足全部数字、唯一、随机和长度可配置要求ID的效率。Since IDs are generated within the range of unused IDs every time, it is guaranteed that the generated IDs meet the uniqueness requirements. When generating IDs, it is not necessary to judge whether the generated IDs will be repeated, so it greatly improves the ability to generate all numbers, uniqueness, randomness and The length is configurable to require the efficiency of the ID.

由于产生满足全部数字、唯一、随机和长度可配置要求的ID与计算机系统的当前时间戳无关,在单位时间内可以产生大量满足要求的ID,所以能够满足大数据量业务应用的要求。Since the generation of IDs that meet the requirements of all numbers, uniqueness, randomness, and configurable length has nothing to do with the current time stamp of the computer system, a large number of IDs that meet the requirements can be generated within a unit of time, so it can meet the requirements of large data volume business applications.

附图说明Description of drawings

图1为本发明产生ID总体技术方案的实现流程图;Fig. 1 is the realization flow diagram that the present invention produces ID overall technical scheme;

图2为本发明一个实施例中产生ID的方法流程图。Fig. 2 is a flowchart of a method for generating an ID in an embodiment of the present invention.

具体实施方式Detailed ways

为使本发明的目的、技术方案和优点更加清楚明白,以下举实施例,并参照附图,对本发明进一步详细说明。In order to make the object, technical solution and advantages of the present invention clearer, the following examples are given and the present invention is further described in detail with reference to the accompanying drawings.

本发明的核心内容是:通过配置ID的取值范围,根据ID的可用性划分ID的取值区间,并利用随机函数在所划分的任意一个取值区间中任取一个ID作为新产生的ID,能够产生满足全部数字、唯一、随机和长度可配置要求的ID。The core content of the present invention is: by configuring the value range of the ID, dividing the value range of the ID according to the usability of the ID, and using a random function to randomly select an ID in any of the divided value ranges as a newly generated ID, Ability to generate IDs that meet all numeric, unique, random and length configurable requirements.

如图1所示,图1为本发明产生ID总体技术方案的实现流程图,该方法包括以下步骤:As shown in Figure 1, Figure 1 is a flowchart of the realization of the overall technical solution for ID generation in the present invention, and the method includes the following steps:

步骤101:配置ID的取值范围,根据ID的可用性划分ID的取值区间;Step 101: configure the value range of the ID, and divide the value range of the ID according to the usability of the ID;

步骤102:在所划分的任意一个取值区间中任取一个ID作为新产生的ID。Step 102: Randomly select an ID from any of the divided value intervals as a newly generated ID.

在上述步骤101中,所述配置ID的取值范围是用户根据实际需要设定ID的最大值和最小值进行的。例如,如果用户根据实际需要希望ID的长度为5,则可以设定ID的最小值为10000,设定ID的最大值为99999,将ID的取值范围配置为[10000,99999]。In the above step 101, the value range of the configuration ID is set by the user according to the actual needs of the maximum and minimum values of the ID. For example, if the user wants the length of the ID to be 5 according to the actual needs, the minimum value of the ID can be set to 10000, the maximum value of the ID can be set to 99999, and the value range of the ID can be configured as [10000, 99999].

所述根据ID的可用性划分ID的取值区间,是在配置的ID的取值范围中根据所有已用的ID确定当前所有可用的ID,将当前所有可用的ID划分为ID值连续的至少一个取值区间。The division of the ID value interval according to the availability of the ID is to determine all currently available IDs according to all used IDs in the configured ID value range, and divide all currently available IDs into at least one with continuous ID values range of values.

例如,如果配置的ID的取值范围为[10000,99999],假设在该取值范围中没有已用的ID,所有的ID都是可用的ID,则将所有可用的ID划分为ID值连续的取值区间为[10000,99999]。假设在该取值范围中10010、11001、25001、33001、52002、68005和95608为全部已用的ID,为了保证产生的ID与已用的ID不发生重复,将ID的取值范围[10000,99999]划分为[10000,10009]、[10011,11000]、[11002,25000]、[25002,33000]、[33002,52001]、[52003,68004]、[68006,95607]和[95609,99999]几个ID值连续的取值区间。For example, if the value range of the configured ID is [10000, 99999], assuming that there are no used IDs in this value range and all IDs are available IDs, then all available IDs are divided into consecutive ID values The range of values is [10000, 99999]. Assuming that 10010, 11001, 25001, 33001, 52002, 68005, and 95608 are all used IDs in this value range, in order to ensure that the generated ID does not overlap with the used ID, set the ID value range [10000, 99999] is divided into [10000, 10009], [10011, 11000], [11002, 25000], [25002, 33000], [33002, 52001], [52003, 68004], [68006, 95607] and [95609, 99999] ] Consecutive value range of several ID values.

在上述步骤102中,所述在所划分的任意一个取值区间中任取一个ID作为新产生的ID包括:先对所划分的所有取值区间进行编号,然后利用随机函数产生编号数目范围内的一个随机数,选择编号与产生的随机数相同的取值区间,判断该取值区间内ID的个数,如果该取值区间内只有一个ID,则取该ID作为新产生的ID;如果该取值区间内有一个以上的ID,则利用随机函数产生该取值区间中ID数目范围内的一个随机数,取该取值区间中与该随机数对应的ID作为新产生的ID。In the above step 102, said randomly selecting an ID in any of the divided value ranges as a newly generated ID includes: first numbering all the divided value ranges, and then using a random function to generate a number within the number range A random number, select the value interval with the same number as the generated random number, and judge the number of IDs in the value interval. If there is only one ID in the value interval, take this ID as the newly generated ID; if If there is more than one ID in the value range, then use a random function to generate a random number within the ID number range in the value range, and take the ID corresponding to the random number in the value range as the newly generated ID.

利用上述产生ID的方法,可以产生一个满足全部数字、唯一、随机和长度可配置要求的ID。如果需要产生多个满足全部数字、唯一、随机和长度可配置要求的ID,该方法进一步包括:根据ID的可用性更新ID的取值区间,在更新后的任意一个取值区间中任取一个ID作为新产生的ID。其中,所述根据ID的可用性更新ID的取值区间包括以下几种情况:Using the method for generating an ID above, an ID that meets the requirements of all numbers, uniqueness, randomness, and configurable length can be generated. If it is necessary to generate multiple IDs that meet the requirements of all numbers, uniqueness, randomness, and configurable length, the method further includes: updating the value interval of the ID according to the availability of the ID, and randomly selecting an ID in any value interval after the update as the newly generated ID. Wherein, the updating of the value interval of the ID according to the availability of the ID includes the following situations:

情况1、如果步骤102中利用随机函数选择的取值区间内只有一个ID,则取该ID作为新产生的ID后,该ID就成为已用的ID,为了保证在下一次产生ID时不会产生与该ID重复的ID,需要将该取值区间直接删除,并对剩余的取值区间重新编号,实现对ID取值区间的更新。Situation 1, if there is only one ID in the value range selected by the random function in step 102, after taking the ID as the newly generated ID, the ID becomes the used ID, in order to ensure that the ID will not be generated next time For IDs that are duplicated with this ID, the value range needs to be deleted directly, and the remaining value ranges should be renumbered to update the ID value range.

情况2、如果步骤102中利用随机函数选择的取值区间内有一个以上的ID,则利用随机函数在该取值区间中任意选取一个ID作为新产生的ID后,选取的这个ID就成为已用的ID,为了保证在下一次产生ID时不会产生与该ID重复的ID,需要将取值区间中的这个ID删除,实现对ID取值区间的更新。此时又有两种情形:Case 2, if there is more than one ID in the value interval selected by the random function in step 102, then utilize the random function to arbitrarily select an ID in the value interval as the newly generated ID, and the selected ID becomes the existing ID. The ID used, in order to ensure that the ID will not be duplicated with the ID when the ID is generated next time, the ID in the value range needs to be deleted to update the ID value range. At this point there are two situations:

情形a、如果在选择的取值区间中将取值区间的一个边界ID作为新产生的ID,则直接删除该取值区间中作为新产生ID的边界ID,即可实现对ID取值区间的更新;Scenario a: If a boundary ID of the value range is used as a newly generated ID in the selected value range, then directly delete the boundary ID in the value range as the newly generated ID, and the ID value range can be realized. renew;

情形b、如果在选择的取值区间中将取值区间的一个非边界ID作为新产生的ID,则删除该取值区间中作为新产生ID的非边界ID,同时将该取值区间划分为两个取值区间,并对所有的取值区间重新编号。Case b. If a non-boundary ID of the value range is used as a newly generated ID in the selected value range, then delete the non-boundary ID as the newly generated ID in the value range, and divide the value range into Two value ranges, and renumber all value ranges.

为了能够更加清楚地说明本发明提供的这种产生ID的方法,以下结合一个具体的实施例,并参照附图对此进行详细说明。In order to more clearly illustrate the method for generating an ID provided by the present invention, a specific embodiment will be combined with a detailed description below with reference to the accompanying drawings.

如图2所示,图2为本发明一个实施例中产生ID的方法流程图。在本实施例中需要产生多个ID,假设用户根据实际需要配置的ID的取值范围为[0,2147483648],在该取值范围内已用的ID为3、5、6、7、12、14和55,该方法包括以下步骤:As shown in FIG. 2, FIG. 2 is a flowchart of a method for generating an ID in an embodiment of the present invention. In this embodiment, multiple IDs need to be generated. Assume that the value range of the ID configured by the user according to the actual needs is [0, 2147483648], and the IDs used within this value range are 3, 5, 6, 7, and 12 , 14 and 55, the method comprises the following steps:

步骤201:为了保证产生的ID与已用的ID不发生重复,根据配置的ID的取值范围[0,2147483648],以及已用的ID 3、5、6、7、12、14和55,将ID的取值范围[0,2147483648]划分为[0,2]、[4,4]、[8,11]、[13,13]、[15,54]、[56,2147483648]等ID值连续的取值区间。Step 201: In order to ensure that the generated ID does not overlap with the used ID, according to the value range of the configured ID [0, 2147483648], and the used ID 3, 5, 6, 7, 12, 14 and 55, Divide the ID value range [0, 2147483648] into [0, 2], [4, 4], [8, 11], [13, 13], [15, 54], [56, 2147483648] and other IDs A continuous range of values.

步骤202:对划分的取值区间[0,2]、[4,4]、[8,11]、[13,13]、[15,54]、[56,2147483648]进行编号,得到表1。   编号   开始区间   结束区间   0   0   2   1   4   4   2   8   11   3   13   13   4   15   54   5   56   2147483648 Step 202: Number the divided value intervals [0, 2], [4, 4], [8, 11], [13, 13], [15, 54], [56, 2147483648] to obtain Table 1 . serial number start interval end interval 0 0 2 1 4 4 2 8 11 3 13 13 4 15 54 5 56 2147483648

                表1 Table 1

步骤203:利用随机函数产生编号数目范围[0,5]内的一个随机数,选择编号与产生的随机数相同的取值区间。Step 203: Use a random function to generate a random number within the number range [0, 5], and select a value interval with the same number as the generated random number.

步骤204:判断选择的用于产生ID的取值区间内ID的个数,如果所选择的取值区间内只有一个ID,则执行步骤205;如果所选择的取值区间内有一个以上的ID,则执行步骤206。Step 204: Judging the number of IDs in the value range selected for generating IDs, if there is only one ID in the selected value range, then perform step 205; if there is more than one ID in the selected value range , then step 206 is performed.

步骤205:取该取值区间内的ID作为新产生的ID,更新表1所述ID的取值区间,然后执行步骤207。Step 205: Take the ID in the value range as the newly generated ID, update the value range of the ID in Table 1, and then execute step 207.

例如,如果利用随机函数产生编号数目范围[0,5]内的随机数为3,则选择编号为3的取值区间[13,13]作为用于产生ID的取值区间,由于该取值区间中只有一个ID 13,则将13作为新产生的ID;在产生该ID后,直接删除编号为3的取值区间,并对剩余的取值区间重新编号,更新后的取值区间如表2所示。   编号   开始区间   结束区间   0   0   2   1   4   4   2   8   11   3   15   54   4   56   2147483648 For example, if a random number within the number range [0, 5] is used to generate a random number of 3, then the value range [13, 13] with the number 3 is selected as the value range for generating the ID, since the value If there is only one ID 13 in the interval, use 13 as the newly generated ID; after generating the ID, directly delete the value interval numbered 3, and renumber the remaining value intervals. The updated value intervals are shown in the table 2. serial number start interval end interval 0 0 2 1 4 4 2 8 11 3 15 54 4 56 2147483648

            表2 Table 2

步骤206:利用随机函数产生所选择的取值区间中ID数目范围内的一个随机数,取该取值区间中与该随机数对应的ID作为新产生的ID,并更新ID的取值区间。Step 206: Use a random function to generate a random number within the range of the number of IDs in the selected value interval, take the ID corresponding to the random number in the value interval as a newly generated ID, and update the value interval of the ID.

例如,如果利用随机函数产生编号数目范围[0,5]内的随机数为4,则选择编号为4的取值区间[15,54]为产生ID的取值区间,由于该取值区间中有40个ID,则利用随机函数产生该取值区间中ID数目范围[0,39]内的一个随机数。For example, if a random number within the number range [0, 5] is used to generate a random number of 4, then the value range [15, 54] with the number 4 is selected as the value range for generating the ID. If there are 40 IDs, use a random function to generate a random number within the range [0, 39] of the number of IDs in the value range.

此时,如果利用随机函数产生该取值区间中ID数目范围[0,39]内的随机数为0,则将取该取值区间中与该随机数0对应的ID作为新产生的ID,这里由于与该随机数0对应的ID为15,即开始区间值15+随机数值0=15,所以将15作为新产生的ID;在产生该ID后,删除该取值区间[15,54]中作为新产生ID的边界ID 15,更新该取值区间为[16,54],更新后的取值区间如表3所示。   编号   开始区间   结束区间   0   0   2   1   4   4   2   8   11   3   13   13   4   16   54   5   56   2147483648 At this time, if the random number within the ID number range [0, 39] in the range of values generated by the random function is 0, then the ID corresponding to the random number 0 in the range of values will be taken as the newly generated ID, Here, because the ID corresponding to the random number 0 is 15, that is, the starting interval value 15+random value 0=15, so 15 is used as the newly generated ID; after generating the ID, delete the value interval [15, 54] As the boundary ID 15 of the newly generated ID, the value interval is updated to [16, 54]. The updated value interval is shown in Table 3. serial number start interval end interval 0 0 2 1 4 4 2 8 11 3 13 13 4 16 54 5 56 2147483648

            表3 table 3

如果利用随机函数产生该取值区间中ID数目范围[0,39]内的随机数为12,则将取该取值区间中与该随机数12对应的ID作为新产生的ID,这里由于与该随机数12对应的ID为27,即开始区间值15+随机数值12=27,所以将27作为新产生的ID;在产生该ID后,删除该取值区间[15,54]中作为新产生ID的非边界ID 27,将该取值区间[15,54]划分为两个取值区间[15,26]和[28,54],并对所有取值区间重新编号,更新后的取值区间如表4所示。   编号   开始区间   结束区间   0   0   2   1   4   4   2   8   11   3   13   13   4   15   26   5   56   2147483648   6   28   54 If a random function is used to generate a random number within the ID number range [0, 39] of the value interval to be 12, then the ID corresponding to the random number 12 in the value interval will be taken as the newly generated ID. The ID corresponding to the random number 12 is 27, that is, the start interval value 15+random value 12=27, so 27 is used as the newly generated ID; after the ID is generated, delete the value interval [15, 54] as the new ID. Generate the non-boundary ID 27 of the ID, divide the value range [15, 54] into two value ranges [15, 26] and [28, 54], and renumber all value ranges, and the updated value range The range of values is shown in Table 4. serial number start interval end interval 0 0 2 1 4 4 2 8 11 3 13 13 4 15 26 5 56 2147483648 6 28 54

                表4 Table 4

步骤207:在更新后的ID的取值区间中,重复执行步骤203~206,产生下一个满足要求的ID,如此反复多次,可以产生多个满足要求的ID。Step 207: Repeat steps 203 to 206 in the updated ID range to generate the next ID that meets the requirements. Repeat this for multiple times to generate multiple IDs that meet the requirements.

以上所述的具体实施例,对本发明的目的、技术方案和有益效果进行了进一步详细说明,所应理解的是,以上所述仅为本发明的具体实施例而已,并不用于限制本发明,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The specific embodiments described above have further described the purpose, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above descriptions are only specific embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.

Claims (7)

1、一种产生标识符的方法,其特征在于,包括以下步骤:1. A method for generating an identifier, comprising the following steps: A、配置标识符ID的取值范围,根据ID的可用性划分ID的取值区间;A. Configure the value range of the identifier ID, and divide the value range of the ID according to the availability of the ID; B、在所划分的任意一个取值区间中任取一个ID作为新产生的ID。B. Randomly select an ID from any of the divided value intervals as a newly generated ID. 2、根据权利要求1所述的方法,其特征在于,步骤A中所述的根据ID的可用性划分ID的取值区间为:2. The method according to claim 1, characterized in that, in step A, according to the availability of the ID, the value range of the ID is divided into: 在配置的ID的取值范围中根据所有已用的ID确定当前所有可用的ID,将当前所有可用的ID划分为ID值连续的至少一个取值区间。In the configured value range of IDs, all currently available IDs are determined according to all used IDs, and all currently available IDs are divided into at least one value interval with continuous ID values. 3、根据权利要求1所述的方法,其特征在于,所述的步骤B包括:3. The method according to claim 1, wherein said step B comprises: B1、对所划分的所有取值区间进行编号;B1. Numbering all the divided value intervals; B2、利用随机函数产生编号数目范围内的一个随机数,选择编号与产生的随机数相同的取值区间,判断所选择用于产生ID的取值区间内ID的个数,如果该取值区间内只有一个ID,则取该ID作为新产生的ID;如果该取值区间内有一个以上的ID,则执行步骤B3;B2. Utilize the random function to generate a random number within the range of the number of numbers, select the same value interval of the number and the generated random number, and judge the number of IDs in the value interval selected for generating the ID, if the value interval If there is only one ID in the value range, then take this ID as the newly generated ID; if there is more than one ID in the value range, then perform step B3; B3、利用随机函数产生该取值区间中ID数目范围内的一个随机数,取该取值区间中与该随机数对应的ID作为新产生的ID。B3. Using a random function to generate a random number within the range of the number of IDs in the range of values, and taking the ID corresponding to the random number in the range of values as a newly generated ID. 4、根据权利要求3所述的方法,其特征在于,所述ID需产生多个,该方法进一步包括:4. The method according to claim 3, wherein multiple IDs need to be generated, and the method further comprises: 根据ID的可用性更新ID的取值区间,在更新后的任意一个取值区间中任取一个ID作为新产生的ID。Update the value range of the ID according to the availability of the ID, and randomly select an ID in any value range after the update as the newly generated ID. 5、根据权利要求4所述的方法,其特征在于,所述产生上一个ID时选择用于产生ID的取值区间内只有一个ID;5. The method according to claim 4, characterized in that there is only one ID in the value interval selected for generating the ID when generating the last ID; 所述更新ID的取值区间为:删除该取值区间,并对剩余的取值区间重新编号。The value interval of updating the ID is: delete the value interval, and renumber the remaining value intervals. 6、根据权利要求4所述的方法,其特征在于,所述产生上一个ID时选择用于产生ID的取值区间内有一个以上的ID,且将该取值区间的一个边界ID作为新产生的ID;6. The method according to claim 4, characterized in that when generating the last ID, there is more than one ID in the value interval selected for generating the ID, and a boundary ID of the value interval is used as the new ID. Generated ID; 所述更新ID的取值区间为:删除该取值区间中作为新产生ID的边界ID,更新该取值区间。The updating of the value interval of the ID is: deleting the boundary ID as a newly generated ID in the value interval, and updating the value interval. 7、根据权利要求4所述的方法,其特征在于,所述产生上一个ID时选择用于产生ID的取值区间内有一个以上的ID,且将该取值区间的一个非边界ID作为新产生的ID;7. The method according to claim 4, characterized in that when generating the last ID, there is more than one ID in the value interval selected for generating the ID, and a non-boundary ID of the value interval is used as newly generated ID; 所述更新ID的取值区间为:删除该取值区间中作为新产生ID的非边界ID,将该取值区间划分为两个取值区间,并对所有取值区间重新编号。The value interval of updating the ID is: delete the non-boundary ID as the newly generated ID in the value interval, divide the value interval into two value intervals, and renumber all the value intervals.
CN200510112526A 2005-09-30 2005-09-30 A way to generate an identifier Expired - Fee Related CN100579133C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN200510112526A CN100579133C (en) 2005-09-30 2005-09-30 A way to generate an identifier

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN200510112526A CN100579133C (en) 2005-09-30 2005-09-30 A way to generate an identifier

Publications (2)

Publication Number Publication Date
CN1874357A true CN1874357A (en) 2006-12-06
CN100579133C CN100579133C (en) 2010-01-06

Family

ID=37484613

Family Applications (1)

Application Number Title Priority Date Filing Date
CN200510112526A Expired - Fee Related CN100579133C (en) 2005-09-30 2005-09-30 A way to generate an identifier

Country Status (1)

Country Link
CN (1) CN100579133C (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102842052A (en) * 2012-08-14 2012-12-26 江苏恒安方信科技有限公司 Identity code generation method
CN102929967A (en) * 2012-10-12 2013-02-13 深圳市华阳信通科技发展有限公司 System and method of generating, storing and searching random number
CN103810557A (en) * 2012-11-15 2014-05-21 航天信息股份有限公司 Invoice verification code generation method and device
CN103838604B (en) * 2013-12-13 2017-01-11 广东星辉天拓互动娱乐有限公司 Method for generating distributed globally unique ID
CN106411955A (en) * 2016-12-01 2017-02-15 微鲸科技有限公司 Modulus m congruence class ring based account generation method
CN107767132A (en) * 2016-08-23 2018-03-06 百度在线网络技术(北京)有限公司 Method and apparatus for generating prepaid card password
CN109325015A (en) * 2018-08-31 2019-02-12 阿里巴巴集团控股有限公司 A kind of extracting method and device of the feature field of domain model
CN115002078A (en) * 2022-05-11 2022-09-02 北京奇艺世纪科技有限公司 ID generation method and device
CN117390610A (en) * 2023-12-13 2024-01-12 中国人民解放军国防科技大学 An identity identifier generation method, system and device

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102842052B (en) * 2012-08-14 2015-10-21 江苏恒安方信科技有限公司 A kind of identity code generating method
CN102842052A (en) * 2012-08-14 2012-12-26 江苏恒安方信科技有限公司 Identity code generation method
CN102929967A (en) * 2012-10-12 2013-02-13 深圳市华阳信通科技发展有限公司 System and method of generating, storing and searching random number
CN102929967B (en) * 2012-10-12 2015-10-14 深圳市华阳信通科技发展有限公司 The system and method for magnanimity generating random number, storage and search
CN103810557A (en) * 2012-11-15 2014-05-21 航天信息股份有限公司 Invoice verification code generation method and device
CN103838604B (en) * 2013-12-13 2017-01-11 广东星辉天拓互动娱乐有限公司 Method for generating distributed globally unique ID
CN107767132B (en) * 2016-08-23 2022-01-14 百度在线网络技术(北京)有限公司 Method and device for generating rechargeable card password
CN107767132A (en) * 2016-08-23 2018-03-06 百度在线网络技术(北京)有限公司 Method and apparatus for generating prepaid card password
CN106411955A (en) * 2016-12-01 2017-02-15 微鲸科技有限公司 Modulus m congruence class ring based account generation method
CN106411955B (en) * 2016-12-01 2019-07-23 微鲸科技有限公司 A kind of account generation method based on mould m congruence class ring
CN109325015B (en) * 2018-08-31 2021-07-20 创新先进技术有限公司 A method and device for extracting feature fields of a domain model
CN109325015A (en) * 2018-08-31 2019-02-12 阿里巴巴集团控股有限公司 A kind of extracting method and device of the feature field of domain model
CN115002078A (en) * 2022-05-11 2022-09-02 北京奇艺世纪科技有限公司 ID generation method and device
CN115002078B (en) * 2022-05-11 2024-04-09 北京奇艺世纪科技有限公司 ID generation method and device
CN117390610A (en) * 2023-12-13 2024-01-12 中国人民解放军国防科技大学 An identity identifier generation method, system and device

Also Published As

Publication number Publication date
CN100579133C (en) 2010-01-06

Similar Documents

Publication Publication Date Title
CN108959386B (en) Distributed global unique ID generation method, device, equipment and storage medium
US8325721B2 (en) Method for selecting hash function, method for storing and searching routing table and devices thereof
CN1282332C (en) A method of fast data packet filtering
CN103338155B (en) A kind of high efficiency filter method of packet
US20130311678A1 (en) Method of encoding a data identifier
CN1874357A (en) Method for generating id symbol
CN109951541A (en) A serial number generation method and server
CN104657432A (en) Method for reducing repetitive rate of converting long address into short addresses
MacDavid et al. Concise encoding of flow attributes in SDN switches
CN101051939A (en) Method and device for realizing network flow load sharing
CN104572994B (en) Method and apparatus for searching for data
CN100578943C (en) An optimized Huffman decoding method and device
CN102769677B (en) Towards IPv6 address setting method and the server of real user identity information
CN1299543A (en) Pseudo-random sequence generator and related methods
CN1585358A (en) Route searching method and system
CN1571352A (en) Method for processing five-membered stream group in network equipment
CN100343851C (en) Database compression and decompression method
CN100502331C (en) A Method of IP Address Management
CN1878164A (en) E.164 number domain name storing and searching method
CN1917667A (en) System for processing numbers and processing method in service of sending grouped short message
CN1744725A (en) Method for memorying data flow in single-board
CN111913956A (en) Unified service coding method and device
CN1889080A (en) Method for searching character string
CN1863210A (en) Apparatus scanning method
CN1866218A (en) Source management method for software system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20100106

Termination date: 20150930

EXPY Termination of patent right or utility model