A resource allocation method and device
By obtaining the initial sequence identifier of the game resource and its subset to which it belongs, and using the nonlinear bijective function generated by prime numbers and original roots for mapping, the problems of slow resource allocation speed and low randomness in the prior art are solved, and efficient and random resource allocation is achieved.
Patent Information
- Application Number
- CN202111576722.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2041-12-21
AI Technical Summary
The existing game resource allocation methods have problems such as high storage resource consumption and low randomness, resulting in slow resource allocation speed and single-point pressure.
By obtaining the target initial sequence identifier of the target resource to be allocated, obtaining the target subset to which it belongs, and obtaining the target nonlinear bijective function based on the prime number and original root of the target subset, this function is used to map the initial sequence identifier to obtain the first allocated sequence identifier.
It realizes saving storage space, improving resource allocation efficiency, and improving the randomness of resource allocation.
Smart Images

Figure CN114247130B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer network technology, and more particularly to a resource allocation method, a resource allocation device, an electronic device, and a computer-readable storage medium. Background Art
[0002] In the game resource allocation scenario, a huge amount of resources need to be allocated to players in a random and non-repetitive manner. For example, digital IDs are allocated to newly registered players, benefits are provided during game operations, and rewards are provided during activities. The existing game resource allocation method is to record the allocated resources, and then randomly allocate the remaining unallocated resources for subsequent resource issuance requests. This method requires resource issuance requests to be processed sequentially to avoid parallel requests being allocated to the same resource, which leads to slow resource allocation and single-point pressure. For example, parallel requests will cause the same resource ID to be allocated to different requests, and the ID must be allocated by locking or sequentially processing requests. Locking is essentially sequential processing. Parallel processing corresponds to multi-point distributed processing, and sequential processing is single-point. If there are many requests and parallel processing is not possible, single-point processing will have performance problems. However, the above method consumes a lot of storage resources and cannot fully realize the randomness of resource allocation. Summary of the invention
[0003] The embodiments of the present application provide a resource allocation method, device, electronic device and computer-readable storage medium to solve the problems of storage resource consumption and low randomness in the game resource allocation scenario in the prior art.
[0004] The present application provides a resource allocation method, including:
[0005] Obtain the target initial sequence identifier of the target resource to be allocated;
[0006] Acquire a target subset to which the target initial sequence identifier belongs, the target subset being a subset including the target initial sequence identifier among a plurality of subsets obtained by pre-segmenting a predetermined integer set;
[0007] Acquire a target nonlinear bijective function corresponding to the target subset, where the target nonlinear bijective function is a nonlinear bijective function that maps any initial sequence identifier corresponding to any resource to be allocated in the target subset;
[0008] The target nonlinear bijective function is used to map the target initial sequence identifier to obtain a first allocation sequence identifier corresponding to the target resource to be allocated.
[0009] Optionally, segmenting the predetermined set of integers includes: segmenting the predetermined set of integers based on the selected prime numbers;
[0010] The method further comprises: obtaining a target prime number corresponding to the target subset and a primitive root of the target prime number, wherein the selected prime number includes the target prime number;
[0011] The obtaining of the target nonlinear bijective function corresponding to the target subset includes: obtaining the target nonlinear bijective function based on the target prime number and the primitive root of the target prime number.
[0012] Optionally, the method further includes: obtaining the selected prime number in advance by the following method:
[0013] For a predetermined integer set [0, n), the prime number set p_list corresponding to the prime number to be selected is set to be empty, and the initial maximum integer b0 that can be represented by the prime number set p_list is set to be 0;
[0014] The prime number p in the preset prime number base set is traversed in the order from large to small, if b0+p0-1≤n, then prime number p0 is added to the prime number set p_list, and b1 is updated to b0+p0-1, wherein the prime number base set comprises the basic prime number in the predetermined number of digits and the primitive root of the basic prime number, and the basic prime number is (2,3,5,7,11,17,37, ..., greater than 2^k and the prime number adjacent to 2^k, k≥3);
[0015] If b1+p1-1≤n, then add prime number p1 to the prime number set p_list, and update b2 to b1+p1-1;
[0016] By analogy, until the prime numbers in the prime number base set all do not satisfy b+p-1≤n, the prime numbers in the prime number set p_list are determined as the selected prime numbers;
[0017] Optionally, segmenting the predetermined set of integers based on the selected prime numbers comprises:
[0018] The predetermined integer set [0, n) is divided into a plurality of subsets corresponding to the selected prime numbers by using the selected prime number, wherein the number of integers contained in each subset in the plurality of subsets is the prime number p corresponding to the subset minus 1.
[0019] Optionally, obtaining a target prime number corresponding to the target subset includes:
[0020] Set the target initial sequence identifier to x, set the basic offset diff to -1, and traverse the selected prime numbers;
[0021] If x≤p-1+diff, the corresponding p is the target prime number; or, if x>p-1+diff, the offset is updated to p-1+diff, and the selected prime number is traversed based on the updated offset until the target prime number is obtained when x≤p-1+diff.
[0022] Optionally, the target nonlinear bijective function is obtained based on the target prime number and the primitive root of the target prime number, including: substituting the target prime number and the primitive root of the target prime number into f(x)=g x-diff (mod p)+diff, where p is a prime number, g is the primitive root of the prime number p, diff is an offset, and x is any resource to be allocated in the target subset;
[0023] Correspondingly, the use of the target nonlinear bijective function to map the target initial sequence identifier to obtain the first allocation sequence identifier corresponding to the target resource to be allocated includes: inputting the target initial sequence identifier into f(x)=g x-diff (mod p)+diff, the obtained mapping result f(x) is the first allocation sequence identifier.
[0024] Optionally, the method further includes: allocating the target resource to be allocated based on the first allocation sequence identifier.
[0025] Optionally, also include:
[0026] Obtaining a target linear bijective function for the predetermined set of integers;
[0027] The first allocation sequence identifier is mapped using the target linear bijective function to obtain a second allocation sequence identifier used for allocating the target resource to be allocated.
[0028] The embodiment of the present application also provides a resource allocation device, which is arranged on a game platform, and includes:
[0029] A target initial sequence identifier acquisition unit, used to acquire a target initial sequence identifier of a target resource to be allocated;
[0030] a target subset acquisition unit, configured to acquire a target subset to which the target initial sequence identifier belongs, wherein the target subset is a subset including the target initial sequence identifier among a plurality of subsets obtained by pre-segmenting a predetermined integer set;
[0031] A nonlinear bijective function acquisition unit, used to acquire a target nonlinear bijective function corresponding to the target subset, wherein the target nonlinear bijective function is a nonlinear bijective function that maps any initial sequence identifier corresponding to any resource to be allocated in the target subset;
[0032] The first allocation sequence identifier obtaining unit is used to map the target initial sequence identifier by using the target nonlinear bijective function to obtain a first allocation sequence identifier corresponding to the target resource to be allocated.
[0033] An embodiment of the present application also provides a device, including: An embodiment of the present application also provides an electronic device, including a processor and a memory; wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the above method.
[0034] An embodiment of the present application also provides a computer-readable storage medium on which one or more computer instructions are stored, and the instructions are executed by a processor to implement the above method.
[0035] Compared with the prior art, the embodiments of the present application have the following advantages:
[0036] The resource allocation method provided in the embodiment of the present application obtains a target initial sequence identifier of a target resource to be allocated; obtains a target subset to which the target initial sequence identifier belongs, the target subset being a subset of multiple subsets obtained by pre-segmenting a predetermined integer set and including the target initial sequence identifier; obtains a target nonlinear bijective function corresponding to the target subset, the target nonlinear bijective function being a nonlinear bijective function that maps any initial sequence identifier corresponding to any resource to be allocated in the target subset; and maps the target initial sequence identifier using the target nonlinear bijective function to obtain a first allocation sequence identifier corresponding to the target resource to be allocated.
[0037] Compared with the existing game resource allocation method that needs to record the allocated resource ID, the resource allocation method provided by the embodiment of the present application only needs to input the corresponding initial sequence identifier for any resource to be allocated, and does not need to record the allocated resource ID, which can save storage space. The present application implements a nonlinear bijective mapping from a segmented subset of an integer set to itself, inputs a resource ID into a nonlinear bijective function, and then obtains a mapping result ID after segmented nonlinear mapping. The process is implemented at a fast speed, making the resource allocation more efficient. The present application first divides a predetermined integer set into multiple subsets, and then uses a nonlinear bijective for each subset to obtain a first allocation sequence identifier, which has higher randomness than the randomness of a linear bijective mapping. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 is a flow chart of a resource allocation method provided in the first embodiment of the present application;
[0039] Figure 1-A It is a schematic diagram of the piecewise nonlinear bijection principle provided in an embodiment of the present application;
[0040] Figure 1-B is a prime number basis set for partitioning any integer set [0, n) provided in an embodiment of the present application;
[0041] Figure 1-C is a graph of the disorder degree after mapping for different values of n provided in the embodiment of the present application;
[0042] Figure 2 is a unit block diagram of a device provided in the second embodiment of the present application;
[0043] Figure 3 It is a schematic diagram of the logical structure of an electronic device provided in the third embodiment of the present application. DETAILED DESCRIPTION
[0044] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.
[0045] It should be noted that the terms "first", "second" and "third" in the various parts and drawings of the embodiments of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. Such data can be interchanged where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than that illustrated or described herein. The terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0046] The difficulty in the game resource allocation scenario is to meet both randomness and non-repetitiveness at the same time. If only non-repetitiveness is met, the resources can be numbered and then allocated sequentially. Each allocation is done in batches to increase the allocation speed. However, this method has poor randomness and cannot meet the requirements of random allocation of game resources.
[0047] To solve the above technical problems, the present invention proposes a new algorithm, constructs a bijective function from an integer set to itself, and realizes the conversion from sequential allocation to random allocation by mapping sequential numbers to random numbers. The algorithm itself is a bijective function of the integer set [0, n), and any integer x in the set can be mapped to another integer y in the set. Its advantages are that it takes up little memory space, has a fast calculation speed, and has a good random mapping effect.
[0048] Therefore, in order to satisfy both randomness and non-repetitiveness during the allocation of online game resources, the present application provides a resource allocation method, a resource allocation device corresponding to the method, an electronic device that can implement the resource allocation method, and a computer-readable storage medium. The following provides embodiments to describe the above method, device, electronic device, and computer-readable storage medium in detail.
[0049] The first embodiment of the present application provides a resource allocation method, the application subject of the method can be a computing device application for allocating online game resources, and the computing device application can be run on a game platform. Figure 1 This is a flowchart of the resource allocation method provided in the first embodiment of the present application. Figure 1 The resource allocation method provided in this embodiment is described in detail. The embodiments described below are used to explain the principle of the method and are not intended to be limiting in actual use.
[0050] like Figure 1 As shown, the resource allocation method provided in this embodiment includes the following steps:
[0051] S101, obtaining a target initial sequence identifier of a target resource to be allocated.
[0052] This step is used to obtain the target initial sequence identifier of the target resource to be allocated. In the game resource allocation scenario, the resource to be allocated can be the serial number value allocated to the player (the digital ID of the game player), the welfare ID released in the game operation, the reward ID released in the activity, etc. For example, the digital ID to be issued to the player in the game platform can be in the interval of 0-10000000000, and the target initial sequence identifier x is a value in the interval. The starting value of x can be 0. When a new player requests to obtain the digital ID, x can be updated to x+1 in sequence. The purpose of the embodiment of the present application is to use the resource allocation method to calculate the target allocation sequence identifier y value based on the target initial sequence identifier x, and allocate the y value to the player to achieve the effect of random allocation, and in the process ensure that x and y are in a one-to-one correspondence, and y will not be repeated, so as to achieve the effect of non-repetitive allocation.
[0053] S102: Obtain the target subset to which the target initial sequence identifier belongs.
[0054] After obtaining the target initial sequence identifier x of the target resource to be allocated in the above step, this step is used to obtain the target subset to which the target initial sequence identifier belongs. The target subset is a subset including the above target initial sequence identifier among multiple subsets obtained by pre-segmenting the predetermined integer set. That is, before executing the above step S101, it is first necessary to segment the predetermined integer set to obtain multiple subsets. The predetermined integer set here is a set of initial sequence identifiers of the resources to be allocated, such as a digital ID in the range of 0-10000000000 to be issued to players in the game platform. The purpose of segmenting the predetermined integer set is to facilitate the subsequent nonlinear bijective mapping of the segmented subsets. The reason is that in order to increase the randomness of the mapping, the present application uses a nonlinear bijective mapping from the integer set to itself. However, in order to solve the nonlinear bijection from the integer set [0, n) to itself for any integer n, it is impossible to directly construct a nonlinear bijection that satisfies any n (that is, it is impossible to construct a nonlinear bijection that is valid for an integer set with any value of n). Therefore, the predetermined integer set is segmented so that each of the obtained subsets can satisfy the nonlinear bijection.
[0055] In the present embodiment, the above-mentioned segmentation of the predetermined integer set specifically refers to: segmenting the predetermined integer set based on the selected prime numbers to obtain the multiple subsets corresponding to the selected prime numbers, and the above-mentioned target subset is a subset containing the above-mentioned target initial sequence identifier among the multiple subsets obtained after the predetermined integer set is segmented based on the selected prime numbers in advance.] That is, the present embodiment adopts the strategy of piecewise nonlinear bijection by constructing a nonlinear bijection based on prime numbers, and for any integer n, the [0, n) integer set is divided into multiple subsets in order based on the selected prime numbers in advance, and each prime number corresponds to a subset. In the present embodiment, the above-mentioned selected prime numbers are obtained in advance in the following manner:
[0056] First, for a predetermined integer set [0, n), the prime number set p_list corresponding to the prime number to be selected is set to be empty, and the representable initial maximum integer b0 of the prime number set p_list is set to be 0;
[0057] Secondly, the prime number p in the preset prime number base set is traversed in the order from big to small, if b0+p0-1≤n, then prime number p0 is added to the prime number set p_list, and b1 is updated to b0+p0-1, if b1+p1-1≤n, then prime number p1 is added to the prime number set p_list, and b2 is updated to b1+p1-1; if b2+p2-1≤n, then prime number p2 is added to the prime number set p_list, and b3 is updated to b2+p2-1; and so on, until the prime numbers in the prime number base set all do not satisfy b+p-1≤n, the prime numbers in the prime number set p_list are determined as the selected prime numbers.
[0058] Wherein, the prime number basis set comprises the basic prime number in the predetermined number of digits and the primitive root of the basic prime number, and the basic prime number is (2,3,5,7,11,17,37, ..., a prime number greater than 2^k and adjacent to 2^k, k≥3); that is, for any integer n, the embodiment of the present application uses the above-mentioned prime number basis to divide the [0,n) integer set, and in the division process, each selected prime number in the prime number basis is only used once. It is similar to the existing representation of any positive integer n with a finite integer set (1,2,4, ..., 2^k). Above-mentioned prime number base is obtained in the following manner: first select basic prime number (2,3,5,7), then select the next prime number p greater than 2^k (greater than 2^k and the prime number adjacent to 2^k, k≥3) and add it in the prime number base, you can obtain the basic prime number of above-mentioned (2,3,5,7,11,17,37, ... greater than 2^k and the prime number adjacent to 2^k, k≥3), and record it as prime number base. In the present embodiment, the prime number base is as follows: Figure 1-B As shown, for any integer n less than or equal to int32, just create Figure 1-B The prime number base in , this set of prime number bases can divide any set of integers less than or equal to int32.
[0059] The primitive roots of the above prime numbers can be obtained in advance and stored in the prime number basis set corresponding to the prime numbers. The primitive roots of the prime numbers can be obtained in advance in the following way: It is known that for prime number p, Fermat's Little Theorem: a p-1 ≡1(mod p); define e p (a) To make a e ≡1(mod p) is the smallest positive integer e for which: (mod p), prove that e p (a)|(p-1). A primitive root of a prime number is an integer g that satisfies e p (g) = p-1, that is, for g 1 , g 2 , ..., g p-1 , the first number modulo p is 1 is gp-1 .
[0060] The segmentation of the predetermined integer set based on the selected prime number may specifically refer to: using the selected prime number to divide the predetermined integer set [0, n) into a plurality of subsets corresponding to the selected prime number, wherein the number of integers contained in each subset of the plurality of subsets is the prime number p corresponding to the subset minus 1. For example Figure 1-A As shown, for integer set [0, 22), it can be determined that the selected prime numbers are 17 and 7 by the above method, and by the selected prime numbers 17 and 7, the integer set [0, 22) is divided into two subsets [0, 16) and [16, 22)], corresponding to prime numbers 17 and 7 respectively.
[0061] In the present embodiment, after obtaining the target subset to which the target initial sequence identifier belongs, it is also necessary to obtain the target prime number corresponding to the target subset and the primitive root of the target prime number. The above-mentioned selected prime number includes the target prime number and can specifically obtain the target prime number corresponding to the target subset in the following manner: setting the target initial sequence identifier to x, setting the basic offset diff to -1, and traversing the selected prime number; if x≤p-1+diff, the corresponding p is the target prime number; or, if x>p-1+diff, updating the offset to p-1+diff, and traversing the selected prime number based on the updated offset until the target prime number is obtained when x≤p-1+diff.
[0062] After obtaining the target prime number, the primitive root of the target prime number can be obtained from the above prime number basis set.
[0063] S103, obtaining a target nonlinear bijective function corresponding to the target subset.
[0064] After the target subset to which the target initial sequence identifier belongs is obtained in the above step, this step is used to obtain the target nonlinear bijective function corresponding to the target subset. Specifically, after the target prime number and the primitive root of the target prime number corresponding to the target subset are obtained, the target nonlinear bijective function can be obtained based on the target prime number and the primitive root of the target prime number. The target nonlinear bijective function is for any initial sequence identifier corresponding to any resource to be allocated in the target subset. Corresponding to the above step S103, this step obtains the target nonlinear bijective function based on the target prime number and the primitive root of the target prime number. Specifically, it can refer to: substituting the target prime number and the primitive root of the target prime number into f(x)=g x-diff (modp)+diff, wherein p is a prime number, g is the primitive root of the prime number p, diff is an offset, and x is any resource to be allocated in the target subset. Since the primitive roots of the prime numbers in the prime number base are calculated in advance, the overhead of instant calculation in this step can be saved.
[0065] In this embodiment, the nonlinear bijective function is obtained as follows:
[0066] For the primitive root g of a prime number, there is a sequence 1: g 1 , g 2 , ..., g p-1 (mod p) is the same as sequence 2: 1, 2, ..., p-1 (mod p). The proof is as follows: First, the two sequences have the same number of elements. The elements in sequence 2 are obviously different. We only need to prove that the elements in sequence 1 are different from each other. Using the proof by contradiction, suppose there are integers i and j, where 1≤i≤j≤p-1 such that g i ≡ j (modp), so g j-i ≡1(mod p), and ji<p-1, which contradicts the definition that g is a primitive root of a prime number, so the sequence 1 is the same as the sequence 2, only the order is different. Therefore, for the integer set [1, p) there is the following nonlinear bijective function:
[0067] f(x)=g x (mod p) where x∈[1,p) is an integer and g is a primitive root of the prime number p.
[0068] S104: Use the target nonlinear bijective function to map the target initial sequence identifier to obtain a first allocation sequence identifier corresponding to the target resource to be allocated.
[0069] Corresponding to the target nonlinear bijective function corresponding to the target subset obtained in the above step S103, this step is used to use the target nonlinear bijective function to map the above target initial sequence identifier to obtain the first allocation sequence identifier corresponding to the target resource to be allocated. The target resource to be allocated can be allocated based on the first allocation sequence identifier, that is, the target resource to be allocated is allocated with the first allocation sequence identifier as the allocation order. The above process can be specifically: the target initial sequence identifier is determined as x, and input f(x) = g x-diff (mod p)+diff, the obtained mapping result f(x) is the first allocation sequence identifier.
[0070] In the existing resource allocation mode, it is necessary to record the allocated resource ID, so as to avoid the allocated resource ID being allocated again, and a large amount of memory space or database storage space will be occupied when there are massive allocated resource IDs. The resource allocation method provided by the embodiment of the present application only records the parameters (prime number basis) of the nonlinear bijective function, does not need to record the allocated resource ID, and only inputs the target initial sequence identifier during mapping, so compared with the existing resource allocation mode, the embodiment of the present application can effectively save storage space. What the embodiment of the present application realizes is the nonlinear bijective mapping of the subset of the integer set after segmentation to itself, and the calculation process is: input the resource ID to the nonlinear bijective function, and then obtain the mapping result ID after the segmented nonlinear mapping, and the calculation process is constant time, so the speed is fast, and the resource allocation efficiency is improved. The embodiment of the present application first divides the predetermined integer set [0, n) into multiple subsets, and then adopts the nonlinear bijective based on the prime number primitive root for each subset, so as to obtain the final mapping result, and the randomness of its mapping result is higher than the linear bijective mapping.
[0071] For the predetermined integer set [0, n), since the process of mapping x to obtain the first allocation sequence identifier is a nonlinear mapping of the integers in each subset after segmentation, different subsets are mapped to themselves. Therefore, for the resources to be allocated in each subset, its initial sequence identifier and mapping result can only be randomly disordered within the subset, but cannot be randomly disordered in the predetermined integer set [0, n). Therefore, in another embodiment of the present application, after obtaining the first allocation sequence identifier corresponding to the target resource to be allocated in the above step S104, a target linear bijective function for the above predetermined integer set can also be obtained, and the target linear bijective function is used to map the above first allocation sequence identifier to obtain a second allocation sequence identifier for allocating the target resource to be allocated. For example, the first allocation sequence identifier is input as an independent variable into the following target linear bijective function:
[0072] f(x)=(p'x+1)mod n where x∈[0,n) is an integer and p' is relatively prime to n
[0073] The mapping result obtained is the second allocation sequence identifier, and the target resource to be allocated is allocated based on the second allocation sequence identifier. In this embodiment, the bijection algorithm for the integer set [0, n) to itself is a composite function of a piecewise nonlinear bijection based on the primitive root of a prime number and a linear bijection based on a prime modulus, that is, the predetermined integer set [0, n) is a set of initial sequence identifiers of the resources to be allocated, and the target resource to be allocated is an integer x in the predetermined integer set [0, n). For an integer x in a given predetermined integer set [0, n), the process of obtaining its mapping result y (the allocation order corresponding to the target resource to be allocated) is: first, through the target nonlinear bijection function corresponding to the target subset to which the integer x belongs, x is mapped to obtain the first allocation sequence identifier x', and then through the target linear bijection function, x' is linearly bijectively mapped to obtain y. This method combines the advantages of piecewise nonlinear bijection and linear bijection, and through this composite bijection mapping, a higher mapping randomness can be obtained.
[0074] Taking the ordered array [0, 1, 2, ..., n-1] as an example, the bijective mapping result [a0, a1, a2, ..., an-1] is obtained by the above method provided in the embodiment of the present application, and the percentage c of the reverse order pairs in the total number pairs is calculated. The closer c is to 0% and 100%, the worse the randomness of the mapping result. The chaos degree h is defined as c*(1-c) / 0.25. It can be seen that h is in [0, 1], and the closer it is to 1, the higher the randomness, such as Figure 1-C As shown, for integers n with different values, the final degree of confusion is close to 1. Therefore, the resource allocation method provided in the embodiment of the present application has a higher randomness in the mapping result.
[0075] The above target linear bijective function can be obtained as follows:
[0076] For the integer set [0, n), for any p' and n are mutually prime, sequence 1: 1*p', 2*p', ..., (n-1)*p' (mod n) is the same as sequence 2: 1, 2, ..., n-1 (mod n). The proof process is: first, the number of elements in the two sequences is the same, and the elements in sequence 2 are obviously different. It is only necessary to prove that the elements in sequence 1 are different from each other. Using the inverse method, assume that there are two numbers in sequence 1 that are congruent, that is, kp≡jp (mod n), where j<k<n, then n|(kj)p', and because n and p' are mutually prime, so n|(kj), and k<n, so k=j, this result contradicts the above assumption, so it can be determined that there are no two numbers in sequence 1 that are congruent. Therefore, the elements in sequence 1 and sequence 2 are the same, only the order is different. Therefore, the target linear bijective function can be obtained:
[0077] f(x)=(p'x+1)mod n, where x∈[0,n) is an integer and p' is relatively prime to n.
[0078] In this embodiment, for any given integer n, a method of selecting p' that is relatively prime to the integer n may be as follows: for any integer n, traverse the following list: [1000003 2000029 3110011 4010021 5001023 600700377000711], and find a prime number relatively prime to n.
[0079] The first embodiment above provides a resource allocation method. Correspondingly, the second embodiment of the present application also provides a resource allocation device, which can be applied to the server of the game platform in the form of software or hardware to perform game resource allocation. Since the device embodiment is basically similar to the method embodiment, the description is relatively simple. For the details of the relevant technical features, please refer to the corresponding description of the method embodiment provided above. The following description of the device embodiment is only illustrative.
[0080] Please refer to Figure 2 To understand this embodiment, the figure is a unit block diagram of the resource allocation device provided in this embodiment. As shown in the figure, the resource allocation device provided in this embodiment includes:
[0081] A target initial sequence identifier acquisition unit 201 is used to acquire a target initial sequence identifier of a target resource to be allocated;
[0082] A target subset acquisition unit 202 is used to acquire a target subset to which the target initial sequence identifier belongs, wherein the target subset is a subset including the target initial sequence identifier among a plurality of subsets obtained by pre-segmenting a predetermined integer set;
[0083] A nonlinear bijective function acquisition unit 203 is used to acquire a target nonlinear bijective function corresponding to the target subset, wherein the target nonlinear bijective function is a nonlinear bijective function that maps any initial sequence identifier corresponding to any resource to be allocated in the target subset;
[0084] The first allocation sequence identifier obtaining unit 204 is configured to map the target initial sequence identifier using the target nonlinear bijective function to obtain a first allocation sequence identifier corresponding to the target resource to be allocated.
[0085] The segmenting of the predetermined integer set includes: segmenting the predetermined integer set based on the selected prime numbers;
[0086] The method further comprises: obtaining a target prime number corresponding to the target subset and a primitive root of the target prime number, wherein the selected prime number includes the target prime number;
[0087] The obtaining of the target nonlinear bijective function corresponding to the target subset includes: obtaining the target nonlinear bijective function based on the target prime number and the primitive root of the target prime number.
[0088] The device also includes: a selected prime number obtaining unit, which is used to obtain the selected prime number in advance by the following method:
[0089] For a predetermined integer set [0, n), the prime number set p_list corresponding to the prime number to be selected is set to be empty, and the initial maximum integer b0 that can be represented by the prime number set p_list is set to be 0;
[0090] The prime number p in the preset prime number base set is traversed in the order from large to small, if b0+p0-1≤n, then prime number p0 is added to the prime number set p_list, and b1 is updated to b0+p0-1, wherein the prime number base set comprises the basic prime number in the predetermined number of digits and the primitive root of the basic prime number, and the basic prime number is (2,3,5,7,11,17,37, ..., greater than 2^k and the prime number adjacent to 2^k, k≥3);
[0091] If b1+p1-1≤n, then add prime number p1 to the prime number set p_list, and update b2 to b1+p1-1;
[0092] By analogy, until the prime numbers in the prime number base set all do not satisfy b+p-1≤n, the prime numbers in the prime number set p_list are determined as the selected prime numbers.
[0093] Optionally, segmenting the predetermined set of integers based on the selected prime numbers comprises:
[0094] The predetermined integer set [0, n) is divided into a plurality of subsets corresponding to the selected prime numbers by using the selected prime number, wherein the number of integers contained in each subset in the plurality of subsets is the prime number p corresponding to the subset minus 1.
[0095] Optionally, obtaining a target prime number corresponding to the target subset includes:
[0096] Set the target initial sequence identifier to x, set the basic offset diff to -1, and traverse the selected prime numbers;
[0097] If x≤p-1+diff, the corresponding p is the target prime number; or, if x>p-1+diff, the offset is updated to p-1+diff, and the selected prime number is traversed based on the updated offset until the target prime number is obtained when x≤p-1+diff.
[0098] Optionally, the target nonlinear bijective function is obtained based on the target prime number and the primitive root of the target prime number, including: substituting the target prime number and the primitive root of the target prime number into f(x)=g x-diff (mod p)+diff, where p is a prime number, g is the primitive root of the prime number p, diff is an offset, and x is any resource to be allocated in the target subset;
[0099] Correspondingly, the use of the target nonlinear bijective function to map the target initial sequence identifier to obtain the first allocation sequence identifier corresponding to the target resource to be allocated includes: inputting the target initial sequence identifier into f(x)=g x-diff (mod p)+diff, the obtained mapping result f(x) is the first allocation sequence identifier.
[0100] Optionally, the device further includes: a resource allocation unit, configured to allocate the target resource to be allocated based on the first allocation sequence identifier.
[0101] Optionally, the device also includes: a target linear bijective function acquisition unit, used to obtain the target linear bijective function for the predetermined integer set; a second allocation sequence identifier acquisition unit, used to map the first allocation sequence identifier using the target linear bijective function to obtain a second allocation sequence identifier for allocating the target resource to be allocated.
[0102] By using the resource allocation device provided in the embodiment of the present application, the storage space of the server of the game platform can be saved, and the resource allocation process can be made more efficient and the resource allocation effect can have a higher randomness.
[0103] In the above embodiment, a resource allocation method and a resource allocation device are provided. In addition, the third embodiment of the present application also provides an electronic device. Since the electronic device embodiment is basically similar to the method embodiment, the description is relatively simple. For details of the relevant technical features, please refer to the corresponding description of the method embodiment provided above. The following description of the electronic device embodiment is merely illustrative.
[0104] The electronic device embodiment is as follows:
[0105] Please refer to Figure 3 To understand this embodiment, Figure 3 A schematic diagram of the logical structure of the electronic device provided in this embodiment.
[0106] like Figure 3 As shown, the electronic device provided in this embodiment includes: a processor 301 and a memory 302;
[0107] The memory 302 is used to store computer instructions for executing the game scene display method. When the computer instructions are read and executed by the processor 301, the following operations are performed: obtaining the target initial sequence identifier of the target resource to be allocated; obtaining the target subset to which the target initial sequence identifier belongs, the target subset being a subset of multiple subsets obtained by pre-segmenting a predetermined integer set and containing the target initial sequence identifier; obtaining the target nonlinear bijective function corresponding to the target subset, the target nonlinear bijective function being a nonlinear bijective function that maps any initial sequence identifier corresponding to any resource to be allocated in the target subset; using the target nonlinear bijective function to map the target initial sequence identifier to obtain a first allocation sequence identifier corresponding to the target resource to be allocated.
[0108] Compared with the existing resource allocation method, by using the electronic device provided by this embodiment, storage space can be effectively saved, resource allocation efficiency can be improved, and the randomness of the mapping result is higher than the randomness of the linear bijective mapping.
[0109] In the above-mentioned embodiments, a resource allocation method, a resource allocation device and an electronic device are provided. In addition, the fourth embodiment of the present application further provides a computer-readable storage medium for implementing the above-mentioned resource allocation method. The computer-readable storage medium embodiment provided in the present application is described in a relatively simple manner. For the relevant parts, please refer to the corresponding description of the above-mentioned method embodiment. The embodiments described below are merely illustrative.
[0110] The computer-readable storage medium provided in this embodiment stores computer instructions, and when the instructions are executed by a processor, the following steps are implemented: obtaining a target initial sequence identifier of a target resource to be allocated; obtaining a target subset to which the target initial sequence identifier belongs, the target subset being a subset including the target initial sequence identifier among multiple subsets obtained by pre-segmenting a predetermined integer set; obtaining a target nonlinear bijective function corresponding to the target subset, the target nonlinear bijective function being a nonlinear bijective function that maps any initial sequence identifier corresponding to any resource to be allocated in the target subset; and mapping the target initial sequence identifier using the target nonlinear bijective function to obtain a first allocation sequence identifier corresponding to the target resource to be allocated.
[0111] By executing the computer instructions stored on the computer-readable storage medium provided in this embodiment, storage space can be effectively saved, resource allocation efficiency can be improved, and the randomness of the mapping result is higher than the randomness of the linear bijective mapping.
[0112] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0113] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0114] 1. Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include non-transitory media such as modulated data signals and carrier waves.
[0115] 2. Those skilled in the art should understand that the embodiments of the present application can be provided as methods, systems or computer program products. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0116] Although the present application is disclosed as above in the form of a preferred embodiment, it is not intended to limit the present application. Any technical personnel in this field may make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be based on the scope defined by the claims of the present application.
Claims
1. A resource allocation method, characterized in that: include: Obtain the target initial sequence identifier of the target resource to be allocated; Acquire a target subset to which the target initial sequence identifier belongs, the target subset being a subset including the target initial sequence identifier from a plurality of subsets obtained by pre-segmenting a predetermined integer set, the plurality of subsets obtained all being able to satisfy nonlinear bijection, and the predetermined integer set being a set of initial sequence identifiers of resources to be allocated; Acquire a target nonlinear bijective function corresponding to the target subset, where the target nonlinear bijective function is a nonlinear bijective function that maps any initial sequence identifier corresponding to any resource to be allocated in the target subset; Mapping the target initial sequence identifier using the target nonlinear bijective function to obtain a first allocation sequence identifier corresponding to the target resource to be allocated; Allocating the target resources to be allocated using the first allocation sequence identifier as the allocation order of the target resources to be allocated; The segmenting of the predetermined integer set comprises: segmenting the predetermined integer set based on the selected prime numbers to obtain the plurality of subsets corresponding to the selected prime numbers; The method further comprises: obtaining a target prime number corresponding to the target subset and a primitive root of the target prime number, wherein the selected prime number includes the target prime number; The obtaining of the target nonlinear bijective function corresponding to the target subset includes: obtaining the target nonlinear bijective function based on the target prime number and the primitive root of the target prime number.
2. The resource allocation method according to claim 1, characterized in that: Also includes: The selected prime number is obtained in advance in the following manner: For a predetermined integer set [0, n), the prime number set p_list corresponding to the prime number to be selected is set to be empty, and the initial maximum integer b0 that can be represented by the prime number set p_list is set to 0; In order from large to small, the prime number p in the preset prime number basis set is traversed, if b0+p0-1≤n, then prime number p0 is added to the prime number set p_list, and b1 is updated to b0+p0-1, wherein the prime number basis set comprises the basic prime number in a predetermined number of digits and the primitive root of the basic prime number; If b1+p1-1≤n, then add prime number p1 to the prime number set p_list, and update b2 to b1+p1-1; By analogy, until the prime numbers in the prime number base set all do not satisfy b+p-1≤n, the prime numbers in the prime number set p_list are determined as the selected prime numbers.
3. The resource allocation method according to claim 2, characterized in that: The step of segmenting a predetermined set of integers based on the selected prime numbers comprises: The predetermined integer set [0, n) is divided into a plurality of subsets corresponding to the selected prime numbers by using the selected prime number, wherein the number of integers contained in each subset in the plurality of subsets is the prime number p corresponding to the subset minus 1.
4. The resource allocation method according to claim 1, characterized in that: The obtaining of the target prime number corresponding to the target subset includes: Set the target initial sequence identifier to x, set the basic offset diff to -1, and traverse the selected prime numbers; if , then the corresponding p is the target prime number; or, if x>p-1+diff, then the offset is updated to , and traverse the selected prime numbers based on the updated offset until , the target prime number is obtained.
5. The resource allocation method according to claim 1, characterized in that: The method of obtaining a target nonlinear bijective function based on the target prime number and the primitive root of the target prime number comprises: substituting the target prime number and the primitive root of the target prime number into f(x)= , where p is a prime number, g is the primitive root of the prime number p, diff is an offset, and x is any resource to be allocated in the target subset; Correspondingly, the use of the target nonlinear bijective function to map the target initial sequence identifier to obtain the first allocation sequence identifier corresponding to the target resource to be allocated includes: inputting the target initial sequence identifier into f(x)= , the obtained mapping result f(x) is the first allocation sequence identifier.
6. The resource allocation method according to claim 1, characterized in that: Also includes: The target resource to be allocated is allocated based on the first allocation sequence identifier.
7. The resource allocation method according to claim 1, characterized in that: Also includes: Obtaining a target linear bijective function for the predetermined set of integers; The first allocation sequence identifier is mapped using the target linear bijective function to obtain a second allocation sequence identifier used for allocating the target resource to be allocated.
8. A resource allocation device, which is arranged on a game platform, characterized in that: The device comprises: A target initial sequence identifier acquisition unit, used to acquire a target initial sequence identifier of a target resource to be allocated; a target subset acquisition unit, configured to acquire a target subset to which the target initial sequence identifier belongs, wherein the target subset is a subset including the target initial sequence identifier from among multiple subsets obtained by pre-segmenting a predetermined integer set, wherein the multiple subsets obtained can all satisfy nonlinear bijection, and the predetermined integer set is a set of initial sequence identifiers of resources to be allocated; A nonlinear bijective function acquisition unit, used to acquire a target nonlinear bijective function corresponding to the target subset, wherein the target nonlinear bijective function is a nonlinear bijective function that maps any initial sequence identifier corresponding to any resource to be allocated in the target subset; A first allocation sequence identifier obtaining unit, configured to map the target initial sequence identifier using the target nonlinear bijective function to obtain a first allocation sequence identifier corresponding to the target resource to be allocated; a resource allocation unit, configured to allocate the target resources to be allocated by using the first allocation sequence identifier as an allocation order of the target resources to be allocated; The segmenting of the predetermined integer set comprises: segmenting the predetermined integer set based on the selected prime numbers to obtain the plurality of subsets corresponding to the selected prime numbers; The device also includes a target prime number and a primitive root acquisition unit of the target prime number, and the target prime number and the primitive root acquisition unit of the target prime number are used to obtain the target prime number corresponding to the target subset and the primitive root of the target prime number, and the selected prime number includes the target prime number; The obtaining of the target nonlinear bijective function corresponding to the target subset includes: obtaining the target nonlinear bijective function based on the target prime number and the primitive root of the target prime number.
9. An electronic device, characterized in that: comprising a processor and a memory; wherein, The memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the method according to claims 1-7.
10. A computer-readable storage medium having one or more computer instructions stored thereon, characterized in that: The instructions are executed by the processor to implement the method according to claims 1-7.
Citation Information
Patent Citations
Service transmission method and apparatus
CN108292980A
Resource management method and device
CN108664320A