Random number acquisition method, storage method, device, electronic device and medium

By constructing a tree structure to store random number information and accessing nodes layer by layer to obtain random numbers of target leaf nodes, the problem of low acquisition efficiency in the random number storage structure is solved, and efficient acquisition of random numbers is achieved.

CN114625338BActive Publication Date: 2025-08-26TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202011455032.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-10
Publication Date
2025-08-26
Estimated Expiration
2040-12-10

AI Technical Summary

Technical Problem

In a random number storage structure, as the number of unacquited random numbers decreases, the efficiency of obtaining random numbers is inefficient, and in the prior art, it may be necessary to access multiple storage locations to obtain random numbers.

Method used

A tree structure is constructed. Each leaf node stores the information of random numbers. The parent node stores the values ​​calculated based on the information of the leaf node. By accessing the root node and accessing the node layer by layer until the random number of the target leaf node is obtained.

Benefits of technology

The efficiency of random number acquisition is improved, ensuring that when the value stored by the root node is not the set value, the random number of the target leaf node can be obtained through a layer-by-layer access, reducing the number of visits.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114625338B_ABST
    Figure CN114625338B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses a method for obtaining a random number, a storage method, an apparatus, an electronic device and a medium. The method comprises: accessing the root node of a target tree structure, and when the value stored in the root node is not a set value, accessing the nodes of each layer layer by layer until the target leaf node storing the random number information is accessed, and obtaining the random number corresponding to the target leaf node. When the value stored in the root node is not a set value, it is confirmed that the target tree structure corresponds to a random number, and after accessing the nodes of the target tree structure layer by layer, the target leaf node corresponding to the random number that is finally accessed can be obtained, and the random number corresponding to the target leaf node can be obtained, which greatly improves the efficiency of obtaining random numbers.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and more specifically, to a random number storage method, device, electronic device, and storage medium. Background Art

[0002] A random set refers to a collection containing a large number of random numbers. The random numbers in the random set are usually stored in a random number storage structure, and each random number is stored in a corresponding storage location of the random number storage structure. When a random number needs to be obtained, a storage location is usually randomly selected from the random number storage structure and the random number in the storage location is obtained.

[0003] In some scenarios, when retrieving random numbers from the random number storage structure that stores the random set, previously selected random numbers are deleted from the corresponding storage locations. Therefore, when the random number storage structure has a small number of unretrieved random numbers, it is possible that the storage locations accessed multiple times may not contain any random numbers, resulting in low random number retrieval efficiency. Summary of the Invention

[0004] In view of the above problems, the embodiments of the present application propose a random number acquisition method, storage method, device, electronic device and medium to improve the above problems.

[0005] In the first aspect, an embodiment of the present application provides a method for obtaining a random number, the method comprising: accessing the root node of a target tree structure, the target tree structure comprising the root node and N leaf nodes, N being an integer greater than 1, each leaf node being used to store corresponding random number information, the parent node corresponding to the leaf node being used to store a numerical value, the numerical value being obtained based on the random number information stored in the leaf node corresponding to the parent node; when the numerical value stored in the root node is not a set numerical value, accessing each layer of nodes layer by layer until the target leaf node storing the random number information is accessed, and obtaining the random number corresponding to the target leaf node.

[0006] In second aspect, an embodiment of the present application provides a method for storing random numbers, the method comprising: constructing a tree structure based on the number of multiple random numbers, the tree structure comprising multiple leaf nodes and a parent node corresponding to each leaf node; storing the information of the random number corresponding to each leaf node in the leaf node; obtaining a numerical value based on the information of the random number stored in the leaf node corresponding to each parent node, and storing the numerical value in the parent node to obtain a target tree structure.

[0007] In a third aspect, an embodiment of the present application provides a device for obtaining a random number, the device comprising: an access module and an acquisition module. The access module is used to access the root node of a target tree structure, the target tree structure comprising the root node and N leaf nodes, N being an integer greater than 1, each of the leaf nodes being used to store the corresponding random number information, the parent node corresponding to the leaf node being used to store a numerical value, the numerical value being obtained based on the random number information stored in the leaf node corresponding to the parent node. The acquisition module is used to, when the numerical value stored in the root node is not a set numerical value, access each layer of nodes layer by layer until the target leaf node storing the random number information is accessed, and obtain the random number corresponding to the target leaf node.

[0008] In a fourth aspect, an embodiment of the present application provides a random number storage device, the device comprising: a construction module, a first storage module, and a second storage module. The construction module is used to construct a tree structure based on the number of multiple random numbers, the tree structure comprising multiple leaf nodes and parent nodes corresponding to each of the leaf nodes, each leaf node corresponding to at least one random number. The first storage module is used to store the information of the random number corresponding to each leaf node in the leaf node. The second storage module is used to obtain a numerical value based on the information of the random number stored in the leaf node corresponding to each parent node, and store the numerical value in the parent node to obtain a target tree structure.

[0009] In a fifth aspect, an embodiment of the present application provides an electronic device comprising a processor and a memory; one or more programs are stored in the memory and configured to be executed by the processor to implement the above method.

[0010] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, in which program code is stored, wherein the above method is executed when the program code is executed by a processor.

[0011] In a seventh aspect, embodiments of the present application provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device retrieves the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the above-described method.

[0012] The embodiments of the present application provide a method for obtaining a random number, a storage method, a device, an electronic device, and a medium. By accessing the root node of a target tree structure, when the value stored in the root node is not a set value, the target leaf node corresponding to the random number that is finally accessed can be obtained after accessing the nodes of the target tree structure layer by layer, and the random number corresponding to the target leaf node can be obtained. This realizes that when the value stored in the root node is not a set value, it can be confirmed that there is a leaf node corresponding to the random number in the target tree structure, and after accessing the nodes of each layer of the target tree structure layer by layer, the target leaf node corresponding to the random number can be obtained, and the random number corresponding to the target leaf node can be obtained. Compared with the related art method of obtaining random numbers by randomly accessing the storage location in the storage structure, which may require multiple accesses to the random number storage structure to obtain the random number, the method provided by the embodiments of the present application greatly improves the efficiency of obtaining random numbers. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0014] Figure 1 A schematic diagram of game interaction in a related technology proposed in an embodiment of the present application is shown;

[0015] Figure 2 A flowchart of a method for obtaining a random number proposed in one embodiment of the present application is shown;

[0016] Figure 3 A schematic diagram of a target tree structure in an embodiment of the present application is shown;

[0017] Figure 4 Another schematic diagram showing a target tree structure in an embodiment of the present application;

[0018] Figure 5 A schematic diagram showing a target tree structure in an embodiment of the present application is provided;

[0019] Figure 6 A flowchart of a method for obtaining a random number proposed in another embodiment of the present application is shown;

[0020] Figure 7 A diagram showing the relationship between the bit storage structure, random number storage structure, and target tree structure in an embodiment of the present application is shown;

[0021] Figure 8A schematic diagram showing the principle of eliminating random numbers in a related technology proposed in this application is shown;

[0022] Figure 9 Another flow chart of a method for obtaining a random number proposed in an embodiment of the present application is shown;

[0023] Figure 10 Another relationship diagram among the bit storage structure, random number storage structure, and target tree structure in an embodiment of the present application is shown;

[0024] Figure 11 A flowchart of a method for obtaining a random number proposed in another embodiment of the present application is shown;

[0025] Figure 12 A diagram showing the relationship between the random number storage structure and the target tree structure in an embodiment of the present application is shown;

[0026] Figure 13 Another flow chart of a method for obtaining a random number proposed in an embodiment of the present application is shown;

[0027] Figure 14 Another relationship diagram between the random number storage structure and the target tree structure in an embodiment of the present application is shown;

[0028] Figure 15 A flowchart of a random number storage method proposed in another embodiment of the present application is shown;

[0029] Figure 16 Another flow chart of a random number storage method proposed in an embodiment of the present application is shown;

[0030] Figure 17 Another relationship diagram among the bit storage structure, random number storage structure, and target tree structure in an embodiment of the present application is shown;

[0031] Figure 18 Another flow chart of a random number storage method proposed in an embodiment of the present application is shown;

[0032] Figure 19 Another relationship diagram between the random number storage structure and the target tree structure in an embodiment of the present application is shown;

[0033] Figure 20 A structural block diagram of a random number acquisition device proposed in another embodiment of the present application is shown;

[0034] Figure 21 Another structural block diagram of a random number acquisition device proposed in an embodiment of the present application is shown;

[0035] Figure 22Another structural block diagram of a random number acquisition device proposed in an embodiment of the present application is shown;

[0036] Figure 23 A structural block diagram of a random number storage device proposed in another embodiment of the present application is shown;

[0037] Figure 24 A structural block diagram of an electronic device for executing the method according to an embodiment of the present application is shown;

[0038] Figure 25 A storage unit for storing or carrying program codes for implementing the method according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0039] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0040] Random numbers are increasingly used in various fields, such as cryptographic protocols, gaming, finance, simulation, network security, information communications, real estate lottery, and online lotteries. Figure 1 As shown, taking the gaming sector as an example, online games in the gaming sector are generally electronic games in which multiple players interact and entertain each other through a game interaction system on a computer network. The game interaction system consists of a game server 10 and multiple game clients 20. The game clients 20 are terminals (such as computers, mobile phones, and tablet computers) that provide local service programs to clients and need to cooperate with the game server to operate. The game server 10 is a server that provides service software programs such as data calculation, verification, storage, and forwarding functions to the game clients 20. Game developers must ensure its stable operation and normal service functions.

[0041] When playing a massively multiplayer online role-playing game using the game interaction system consisting of the above-mentioned game server 10 and multiple game clients 20, each player can play one or more virtual characters and control the activities and behaviors of the characters in the virtual world of the game. Due to the numerous game modes and the large number of players, many game modes require the use of random functions, such as game lotteries, random character names, random drop rewards, etc. Since the game needs to ensure real-time performance, the random process must have high performance, otherwise it is easy to cause lag, affecting the player's gaming experience.

[0042] In some scenarios, after a random number is obtained, it is necessary to remove the random number stored in the random number storage structure to prevent it from being obtained again next time. In this scenario, as the number of random numbers stored in the random number storage structure decreases, the probability of randomly obtaining a storage location that stores a random number from the random number storage structure will gradually decrease. For example, when the number of unobtained random numbers in the random set only accounts for one-tenth of the total number of random numbers in the storage structure, the probability of obtaining a random number after a single acquisition is also one-tenth. Accordingly, when obtaining a random number, there may be multiple storage locations selected that do not store a random number. Therefore, there is a problem of low efficiency in obtaining random numbers.

[0043] Based on this, the inventor has proposed a method for obtaining random numbers, a storage method, a device, an electronic device and a storage medium after certified research. In this method, a tree structure is constructed based on the number of multiple random numbers, and each leaf node of the tree structure stores the information of the corresponding random number, and each parent node of the tree structure stores the value obtained according to the information stored in the corresponding leaf node, so as to obtain a target tree structure. When a random number needs to be obtained, the root node of the target tree structure is accessed. When the value stored in the root node is not the set value, the nodes of each layer are accessed layer by layer until the target leaf node storing the random number information is accessed, and the random number corresponding to the target leaf node is obtained. When the value stored in the root node is not the set value, it is confirmed that the target tree structure corresponds to the random number, and after accessing the nodes of the target tree structure layer by layer once, the target leaf node corresponding to the random number that is finally accessed can be obtained, and the random number corresponding to the target leaf node can be obtained. Compared with the related art that may require multiple accesses to the random number storage structure to obtain the random number, the present application greatly improves the efficiency of obtaining random numbers.

[0044] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0045] See also Figure 2 , Figure 2 FIG2 is a flowchart of a method for obtaining a random number applicable to an electronic device, which is proposed in one embodiment of the present application. The electronic device may be a user terminal or a server. The method includes:

[0046] S110: Access the root node of the target tree structure.

[0047] Wherein, accessing the root node of the target tree structure may be a step of performing access to the root node when a random number needs to be obtained. For example, in some embodiments, the electronic device (eg Figure 1Upon receiving the random number acquisition instruction, the game server (in the example) accesses the root node of the target tree structure in response to the random number acquisition instruction. In other embodiments, the server may also need to obtain a random number when processing a service request or service data, such as in scenarios such as lottery draws, raffles, game character selection, or key generation, and thus access the root node of the target tree structure.

[0048] The target tree structure includes a root node and N leaf nodes, where N is an integer greater than 1. Each leaf node is used to store information about a corresponding random number, and the parent node corresponding to the leaf node is used to store a value, which is obtained based on the random number information stored in the leaf node corresponding to the parent node. It should be understood that the root node is one of the parent nodes.

[0049] The target tree structure may be an n-ary tree, where n is an integer greater than or equal to 2. An n-ary tree means that each node in the tree can have at most n child nodes. When the target tree structure is an n-ary tree, it may be a complete n-ary tree or a full n-ary tree.

[0050] Random numbers are typically generated using a random seed as input. A random number generator, based on the random seed, generates a large number of random numbers, with no relationship between any two adjacent numbers. A random seed is a computer science term for a random number generated using a true random number (seed) as the initial condition. The large number of random numbers generated using the random seed and random number generator together constitutes a random set.

[0051] Each random number in the random set corresponds to a leaf node in the target tree structure. Each leaf node of the target tree structure can correspond to one or more random numbers. When the target tree structure is a full n-ary tree, there may be leaf nodes that do not correspond to random numbers.

[0052] The maximum number of random numbers corresponding to a leaf node may be multiple, such as 4, 6, 8, 20, 32, or 64. The random number information stored in the leaf node may be the random number corresponding to the leaf node, the number of random numbers corresponding to the leaf node, the identifier of the random number corresponding to the leaf node, or the number of identifiers of random numbers corresponding to the leaf node, wherein the identifier of the random number corresponds to the random number one-to-one.

[0053] The value stored in the parent node may be a value obtained by summing, weighted summing, or summing after normalization of the number of random numbers or the number of random number identifiers in the target leaf node corresponding to the parent node.

[0054] As an implementation method, when the random number information stored in the leaf node of the target tree structure is the number of random numbers or the number of random number identifiers, and the value stored in the parent node is the value obtained by summing the number of random numbers or the number of identifiers stored in the leaf nodes corresponding to the parent node, please refer to Figure 3 , Figure 3 In the example, the target tree structure is a full binary tree. The random number information stored in the leaf nodes of the binary tree from left to right are 2, 3, 4, 2, 3, 0, 1, 3 respectively. Then we can get the following: Figure 2 The value stored in each parent node in .

[0055] As another way, when the leaf nodes of the target tree structure are used to store the random numbers corresponding to each leaf node, and the value stored in the parent node is the value obtained by summing the number of random numbers stored in the child nodes corresponding to the parent node, please refer to Figure 4 , taking the target tree structure as a full binary tree as an example, Figure 4 In the example, each leaf node stores one or more random numbers. Then, the following can be obtained based on the number of random numbers stored in each leaf node: Figure 4 The value stored in each parent node in .

[0056] As another embodiment, when the leaf nodes of the target tree structure are used to store the corresponding random number identifiers, and the value stored in the parent node is the value obtained by summing the number of random number identifiers stored in the child nodes corresponding to the parent node, please refer to Figure 5 , taking the target tree structure as a full binary tree as an example, each leaf node stores one or more identifiers, which are numbers or letters. According to the number of identifiers stored in each leaf node, we can get the following Figure 5 The value stored in each parent node in .

[0057] S120: When the value stored in the root node is not the set value, access the nodes in each layer layer by layer until the target leaf node storing the random number information is accessed, and obtain the random number corresponding to the target leaf node.

[0058] The set value indicates that the target tree structure does not correspond to a random number. For example, the set value can be zero or any negative number, as long as it can indicate that the target tree structure does not correspond to a random number. When the value stored in the root node is not the set value, it indicates that the target number corresponds to a random number.

[0059] There are multiple ways to access nodes at each layer.

[0060] Please refer again Figure 3As a method, when the value stored in the root node is not a set value, the method of accessing each layer of nodes layer by layer may be to access at least one node in each layer of the tree structure layer by layer. Specifically, it may be: accessing the data stored in the child node connected to the root node, and selecting a target child node corresponding to a random number from the child nodes connected to the root node based on the data stored in the child node. When the child node is a leaf node, the data stored in the child node is random number information, and when the child node is not a leaf node, the data stored in the child node is a value. When the target child node is not a leaf node, the target child node is used as a new root node, and the access to the data stored in the child node connected to the root node is returned, and the target child node corresponding to the random number is selected from the child node connected to the root node based on the data stored in the child node, until the selected target child node is a leaf node, and the access to each layer of nodes is completed.

[0061] In this manner, when the target child node stores random number information or the stored value is not a set value, it indicates that the target child node corresponds to a random number. When the data stored in the target child node is a set value, it indicates that the target child node does not correspond to a random number. The method of selecting a target child node corresponding to a random number from the child nodes connected to the root node based on the data stored in the child node can be: obtaining a child node corresponding to a random number based on the data stored in the child node, and selecting a target child node from the child nodes corresponding to the random number.

[0062] Alternatively, the target tree structure can be accessed layer by layer according to preset access rules until a leaf node storing random number information is reached. For example, the preset access rules can include preset weights and weight coefficients for accessing each node, thereby obtaining a preset probability of accessing each node, and accessing each node based on the preset probability of accessing each node. Alternatively, a target probability of accessing each node can be determined based on the preset probability of accessing each node and the information or values ​​stored in each node, and each node can be accessed based on the target probability of accessing each node.

[0063] As another method, the sub-nodes of each layer may be randomly accessed layer by layer. Specifically, the method of randomly accessing the nodes of each layer layer by layer may be: randomly selecting a target sub-node corresponding to a random number from the sub-nodes connected to the root node, and when the target sub-node is not a leaf node, using the target leaf node as the new root node and returning to the step of randomly selecting a target sub-node corresponding to a random number from the sub-nodes connected to the root node until a leaf node corresponding to the random number information is accessed. The presence of a random number in the target sub-node indicates that the target sub-node stores random number information or the stored value is not a set value.

[0064] As another way, sub-nodes may be selected layer by layer according to the values ​​stored in the sub-nodes of each layer until a target leaf node storing random number information is accessed.

[0065] When using this method to access nodes at each layer layer by layer, the specific steps may be: based on the data stored in the multiple child nodes connected to the root node, the probability of accessing each child node is obtained; when the child node is a leaf node, the data stored in the child node is random number information; when the child node is not a leaf node, the data stored in the child node is a numerical value. A target child node is selected based on the probability corresponding to each child node, and the target child node corresponds to a random number. When the target child node is not a leaf node, the target child node is used as the new root node, and the step of obtaining the probability of accessing each child node based on the data stored in the multiple child nodes connected to the root node is returned until the selected target child node is a leaf node, and the random number corresponding to the target leaf node is obtained.

[0066] When selecting a target child node according to the probabilities corresponding to the child nodes, the target node corresponding to the maximum probability value may be selected according to the probabilities corresponding to the nodes.

[0067] Please refer again Figure 3 As an implementation method, the random number information stored in each leaf node is the number of random numbers or the number of identifiers, and the value stored in each parent node is the sum of the numbers stored in each leaf node corresponding to the parent node. When the tree structure is a full binary tree, the method of accessing each layer of child nodes layer by layer can be: compare the values ​​stored in each child node connected to the root node with the value stored in the root node to obtain the ratio corresponding to each node. The ratio corresponding to each node is the probability of accessing each node. Select the target child node with the maximum probability from the probabilities corresponding to each child node, that is, Figure 3 The node with the value of 11 is stored in it. When the target child node is not a leaf node, the target child node is used as the new root node, and the step of comparing the values ​​stored in each child node connected to the root node with the values ​​stored in the root node to obtain the ratio corresponding to each node is returned until the selected target child node is a leaf node, and the number of identifiers corresponding to the target leaf node is obtained. In this method, the leaf node selected is the leaf node with the stored value of 4, that is, Figure 3 The third leaf node from the middle right left to the right.

[0068] There are many ways to obtain the random number corresponding to the target leaf node.

[0069] As a method, when the random number information stored in the leaf node is a random number identifier, the target identifier can be obtained based on the random number identifier, and the random number corresponding to the target identifier can be searched from the random number storage structure.

[0070] As another way, when the random number information stored in the target leaf node is a random number, one or more random numbers can be selected from the random numbers stored in the target leaf node.

[0071] As another way, when the information of the random number stored in the target leaf node is the number of random numbers, and the random numbers are stored in a random number structure, a random number stored in a target position can be selected from multiple storage positions in the random number storage structure corresponding to the target leaf node, or multiple random numbers stored in multiple storage positions in the random number storage structure corresponding to the target leaf node can be obtained, and a random number can be selected from the multiple random numbers as the final random number obtained.

[0072] As another way, when the information of the random number stored in the target leaf node is the number of random number identifiers, and the identifiers are stored in the identifier storage structure, the target storage location can be selected from multiple storage locations of the identifier storage structure corresponding to the target leaf node, and the target identifier corresponding to the target storage location can be obtained, thereby obtaining the random number corresponding to the target identifier.

[0073] The present application provides a method for obtaining a random number. The method accesses the root node of a target tree structure. When the value stored in the root node is not a set value, the method accesses each layer of nodes layer by layer until a target leaf node storing random number information is accessed, and then the random number corresponding to the target leaf node is obtained. This method realizes that when the value stored in the root node is not a set value, it is confirmed that the target tree structure corresponds to the random number. After a single access operation of accessing each layer of the target tree structure layer by layer, the target leaf node corresponding to the random number can be obtained, thereby improving the efficiency of obtaining random numbers.

[0074] See also Figure 6 Another embodiment of the present application provides a method for obtaining a random number, the method comprising:

[0075] Step S210: Access the root node of the target tree structure.

[0076] The target tree structure includes a root node and N leaf nodes, where N is an integer greater than 1. Each leaf node is used to store the corresponding random number information, and the parent node corresponding to the leaf node is used to store a numerical value, which is obtained based on the random number information stored in the leaf node corresponding to the parent node.

[0077] Each random number corresponds to an identifier, and the value stored in each parent node is obtained according to the number of identifiers corresponding to the leaf nodes corresponding to the parent node, and each identifier corresponds to a random number.

[0078] Step S220: When the value stored in the root node is not the set value, access each layer of nodes layer by layer until the target leaf node storing the random number information is accessed, and then search the bit storage structure for a storage location corresponding to the target leaf node as the target storage location.

[0079] The bit storage structure includes multiple storage locations, each of which stores a representation value. The representation value is used to represent whether the storage location where it is located corresponds to an identifier. Each leaf node corresponds to at least one storage location in the bit storage structure.

[0080] As an implementation manner, when the characterization value is a first set value, it indicates that the storage location where the characterization value is located has a corresponding identifier, and when the characterization value is a second set value, it indicates that the storage location where the characterization value is located has no corresponding identifier.

[0081] The first setting value and the second setting value mentioned above can be arbitrarily set values.

[0082] To conserve storage space within the bit storage structure, each storage location may occupy one bit of memory when storing data. That is, the data stored in each storage location is a binary number of "0" or "1." Alternatively, a "1" characterizing value indicates that a random number is associated with the storage location, while a "0" characterizing value indicates that no random number is associated with the storage location. Alternatively, a "0" characterizing value indicates that a random number is associated with the storage location, while a "1" characterizing value indicates that no random number is associated with the storage location.

[0083] Step S230: when the representation value stored in the target storage location is a first set value, obtaining a target identifier corresponding to the target storage location, wherein the first set value represents that the target storage location has an identifier.

[0084] There are multiple ways to obtain the target identifier corresponding to the target storage location.

[0085] As one approach, the target identifier corresponding to the target storage location may be searched from a preset table of correspondences between storage locations and identifiers.

[0086] As a method, the sorting order of each random number in the random set corresponds to the sorting order of each storage location in the bit storage structure. That is, the storage location ranked first in the bit storage structure is used to store the random number ranked first in the random set, the storage location ranked second in the bit storage structure is used to store the random number ranked second in the random set, and the storage location ranked nth in the bit storage structure is used to store the random number ranked nth in the random set, where n is an integer greater than or equal to 2.

[0087] In this manner, a method for obtaining the target identifier corresponding to the target storage location may be: obtaining a sorting sequence number of the target storage location in the bit storage structure, where the sorting sequence number is the target identifier corresponding to the target storage location.

[0088] Step S240: Obtain a random number corresponding to the target identifier.

[0089] There are multiple ways to obtain the random number corresponding to the target identifier.

[0090] As one approach, the random number corresponding to the target identifier may be searched from a preset table of correspondences between identifiers and random numbers.

[0091] Alternatively, the random number can be stored in a random number storage structure, which can be located in memory, on disk, or elsewhere. The random number storage structure has multiple storage locations, each of which is used to store a random number. The random number is identified by the sequence number of the random number storage location corresponding to the random number storage location in the random number storage structure. In this manner, the target storage location corresponding to the target identifier can be searched for, and the random number at the target storage location can be retrieved to obtain the random number corresponding to the target identifier.

[0092] Please refer to Figure 7 , Figure 7 A relationship diagram among a bit storage structure, a random number storage structure, and a target tree structure provided by the present application is shown.

[0093] Among them, the random number storage structure includes multiple storage locations, and each storage location in the random number storage structure is used to store a random number. Each random number corresponds to an identifier, which is the sorting sequence number of the storage location corresponding to the random number stored in the random number storage structure. When there is a storage location that does not store a random number, there is no identifier corresponding to the random number.

[0094] The bit storage structure includes multiple storage locations. Each storage location in the bit storage structure is used to represent a value, and the representation value is "0" or "1". When the representation value is "0", it represents that the storage location where it is located has no corresponding identifier or the corresponding identifier is invalid. When the representation value is "1", it represents that the storage location where it is located has a corresponding identifier. Figure 5 In the example, when the third position from the left in the random number storage structure stores a random tree, and there is no corresponding identifier, the representation value of the third position from the left in the bit storage structure is "0".

[0095] The target number structure is a full binary tree, and each leaf node in the target tree structure corresponds to a storage position in a 4-bit storage structure, that is, the multiple storage positions in the bit storage structure are divided into multiple groups of storage positions in sorted order, each group of storage positions includes four storage positions, the first leaf node on the left of the target tree structure corresponds to the first group of storage positions obtained by the division, the second leaf node on the left of the target tree structure corresponds to the second group of storage positions obtained by the division, and the nth leaf node on the left of the target tree structure corresponds to the nth group of storage positions obtained by the division. The random number information stored in each leaf node is the number of target storage positions with a representation value of "1" stored in a group of storage positions corresponding to the leaf node. It should be noted that when there is a leaf node in the target tree structure that does not correspond to a storage position, the random number information stored in the corresponding leaf node is zero. The value stored in each parent node is the sum of the numbers stored in the corresponding leaf node. Correspondingly, the value stored in the root node is the sum L of the numbers stored in all leaf nodes.

[0096] When obtaining a random number, the root node in the target tree structure is accessed, and the value stored in the root node is obtained as L. When the value is not the set value, the target leaf node storing the random number information is accessed by accessing the nodes of each layer layer by layer. When the target leaf node is the mth leaf node (m is an integer between 1 and n) located on the left side of the target tree structure, and the corresponding stored random number information is the number p of storage locations with a representation value of "1" stored in the storage location corresponding to the leaf node. Find the mth group of storage locations corresponding to the mth leaf node, and obtain a target storage location in the mth group of storage locations in the bit storage structure. When the representation value stored in the target storage location is "1", obtain the target identifier corresponding to the bit storage structure. When the target identifier is "q", obtain the random number from the qth storage location in the random number storage structure. This random number is the random number finally obtained.

[0097] The present application provides a method for obtaining a random number, which accesses the root node of a target tree structure, and when the value stored in the root node is not a set value, confirms that the target tree structure corresponds to a random number, and accesses the nodes of each layer of the target tree structure layer by layer to obtain the target leaf node that stores information about the random number, and obtains the storage position corresponding to the target leaf node in the bit storage structure, so that the representation value stored in the storage position determines the target storage position, and when the target identifier corresponding to the target storage position is obtained, searches for the random number corresponding to the target identifier, thereby achieving the goal of obtaining a random number through one search, thereby improving the efficiency of obtaining random numbers.

[0098] In order to avoid obtaining the same random number in the subsequent random number acquisition process, and to avoid the following Figure 8In the related art, the method for eliminating acquired random numbers is to create a hash table, which includes hash key-value pairs corresponding to each random number. Each hash key-value pair in the hash table includes a key code value to quickly locate the acquired random number. When the acquired random number is eliminated, each hash key-value pair usually occupies 300 bytes of memory. When the number of random numbers included in the random set is large, more hash key-value pairs need to be created, and more memory is occupied, resulting in a linear increase in hardware costs. Please refer to Figure 9 After executing step S240, the method further includes:

[0099] Step S250: adjusting the representation value stored in the target storage location from the first set value to a second set value, where the second set value is used to represent that the target storage location does not correspond to the identifier.

[0100] Step S260: Obtain the number of storage locations storing the first set value in at least one storage location corresponding to the target leaf node, and use the number as information of the random number stored in the target leaf node.

[0101] Step S270: Based on the random number information stored in the target leaf node, update the values ​​stored in each parent node corresponding to the target leaf node in the target tree structure.

[0102] The method for updating the values ​​stored in the parent nodes corresponding to the target leaf nodes in the target structure tree may be: accessing the corresponding parent nodes layer by layer according to the target leaf nodes, and updating each parent node layer by layer. Alternatively, the method may be to calculate the values ​​stored in each parent node based on the random number information in the leaf nodes corresponding to each parent node, and use the calculated values ​​stored in each parent node as the updated values ​​of the parent nodes to complete the update.

[0103] As a way, when Figure 7 After the random number corresponding to the target identifier q is obtained, the representation value stored in the storage location corresponding to the target identifier in the bit storage structure (the qth storage location) is adjusted from "1" to "0". The random number information of the target leaf node is also adjusted from the original value p to P-1, and the parent node corresponding to the target leaf node is adjusted layer by layer. Finally, the value in the adjusted root node is also changed from the original L to L-1, that is, the following is obtained: Figure 10 Another relationship diagram between the bit storage structure, random number storage structure and target tree structure is shown.

[0104] Through the above steps, when the random number in the random set is obtained again in the subsequent process, the target identifier q will not be obtained again, and accordingly, the random number corresponding to the target identifier q will not be obtained again, so that after the random number is obtained, the random number that has been obtained will not be obtained again in the subsequent random number acquisition process.

[0105] After obtaining the random number corresponding to the target identifier, the random number corresponding to the target identifier in the random number storage structure may be deleted to save memory space.

[0106] This method creates a bit storage structure and a target tree structure, and each storage location in the bit storage structure only occupies one bit. When the random set includes 50 million random numbers, a total of 50 million bits are required, and the target number structure occupies less storage space. Compared with the use of hash tables and hash key-value pairs in related technologies, since each hash key-value pair is usually 300 bytes, taking 50 million random numbers as an example, 50 million hash key-value pairs need to be created, and a total of 14GB of memory size is required to store the hash table. Therefore, compared with related technologies, this application greatly saves memory, thereby greatly saving hardware costs.

[0107] See also Figure 11 Another embodiment of the present application provides a method for obtaining a random number, the method comprising:

[0108] Step S310: Access the root node of the target tree structure.

[0109] The target tree structure includes a root node and N leaf nodes, where N is an integer greater than 1. Each leaf node is used to store the corresponding random number information, and the parent node corresponding to the leaf node is used to store a numerical value, which is obtained based on the random number information stored in the leaf node corresponding to the parent node.

[0110] Each random number corresponds to an identifier, and the information of the random number includes the identifier of the random number. The value stored in each parent node is obtained according to the number of identifiers stored in the leaf node corresponding to the parent node.

[0111] Step S320: When the value stored in the root node is not the set value, access each layer of nodes layer by layer until the target leaf node storing the random number information is accessed, and a target identifier is selected from the identifiers stored in the target leaf node.

[0112] The identifier stored in the target leaf node may be one or more. If there are more than one identifier, any one of the identifiers is selected as the target identifier.

[0113] There are various ways to identify a random number. As one approach, the random number identifier can be a unique identifier set for each random number, which can be composed of one or more of a character, a number, and a symbol. Alternatively, the random number identifier can be the sort order of the random number's corresponding storage location in a random number storage structure.

[0114] Step S330: searching for a target storage location corresponding to the target identifier from the random number storage structure. The random number storage structure includes a plurality of storage locations for storing random numbers, and each identifier corresponds to a random number storage location.

[0115] The random number storage structure is any storage structure for storing random numbers, and the random number storage structure may be located in a memory of the electronic device or in a disk of the electronic device.

[0116] Step S340: Obtain the random number stored in the target storage location.

[0117] Please refer to Figure 12 , Figure 12 A diagram showing the correspondence between a random number storage structure and a target tree structure provided by the present application is shown.

[0118] The random number storage structure includes multiple storage locations, the number of which is r, and each location in the random number storage structure is used to store a random number. Each random number has an identifier corresponding to it, which is the sorting sequence number of the storage location corresponding to the random number in the random number storage structure.

[0119] The target number structure is a full binary tree. Each leaf node in the target tree structure corresponds to a storage location in four random number storage structures, that is, the multiple storage locations in the random number storage structure are divided into multiple groups of storage locations in sorted order. Each group of storage locations includes four storage locations. The first leaf node on the left of the target tree structure corresponds to the first group of storage locations obtained by the division. The second leaf node on the left of the target tree structure corresponds to the second group of storage locations obtained by the division. The nth leaf node on the left of the target tree structure corresponds to the nth group of storage locations obtained by the division. The random number information stored in each leaf node is the random number stored in a group of storage locations corresponding to the leaf node. It should be noted that when there is a leaf node in the target tree structure that does not correspond to a storage location, the random number information stored in the corresponding leaf node is empty. The value stored in each parent node is the sum of the number of random numbers stored in the corresponding leaf node. Correspondingly, the value stored in the root node is the sum L of the numbers stored in all leaf nodes.

[0120] When obtaining a random number, the root node in the target tree structure is accessed, and the value stored in the root node is obtained as L. When the value is not the set value, the target leaf node storing the random number information is accessed by accessing each layer of nodes layer by layer. When the target leaf node is the mth leaf node on the left side of the target tree structure (m is an integer between 1 and n), and the corresponding stored random number information is a random number identifier, a target identifier is arbitrarily selected from the number identifiers. When the target identifier is "q", the random number is obtained from the qth storage position in the random number storage structure, and the random number is the final random number obtained.

[0121] The present application provides a method for obtaining a random number. The method accesses the root node of a target tree structure, and when the value stored in the root node is not a set value, confirms that the target tree structure corresponds to a random number, and accesses the nodes of each layer of the target tree structure layer by layer to obtain the target leaf node that stores the information of the random number. When obtaining the target identifier stored in the target leaf node, the method searches for the random number corresponding to the target identifier, thereby achieving the goal of obtaining a random number through a single search, thereby improving the efficiency of obtaining random numbers.

[0122] In order to avoid obtaining the same random number in the subsequent random number acquisition process, and to avoid the following Figure 8 In the related art, the method of eliminating the acquired random numbers is to create a hash table. After using the hash table to quickly locate the acquired random numbers, when the acquired random numbers are eliminated, there is a problem that when the number of random numbers included in the random set is large, more hash key-value pairs need to be created, and more memory is occupied, resulting in a linear increase in hardware costs. Figure 13 , the method further comprises:

[0123] Step S350: Delete the target identifier stored in the target leaf node to obtain the identifier of the adjusted random number.

[0124] Step S360: Based on the identifier of the adjusted random number stored in the target leaf node, update the values ​​stored in each parent node corresponding to the target leaf node in the target tree structure.

[0125] Since the target identifier stored in the target leaf node is deleted, the number of identifiers stored in the corresponding target leaf node decreases. The method for updating the values ​​stored in each parent node corresponding to the target leaf node in the target structure tree can be: accessing the corresponding parent node layer by layer according to the target leaf node, and updating each parent node layer by layer. Alternatively, the method can be: obtaining the corresponding stored values ​​of each parent node based on the random number information in the leaf node corresponding to each parent node, and using the corresponding stored values ​​of each parent node as the updated parent node values ​​to complete the updating of the values ​​stored in each parent node corresponding to the target leaf node in the target structure tree.

[0126] As a way, when Figure 12 After the random number corresponding to the target identifier q is obtained, the target identifier in the target leaf node is deleted, and the number of identifiers stored in the corresponding target leaf node changes. The parent node corresponding to the target tree structure is adjusted layer by layer according to the number of identifiers in the target leaf node, such as Figure 14 As shown in FIG, the value in the root node after the final adjustment is changed from the original L to L-1.

[0127] Through the above method, when the random number in the random set is obtained again in the subsequent process, the target identifier q will not be obtained again, and accordingly, the random number corresponding to the target identifier q will not be obtained again, so that after the random number is obtained, the random number that has been obtained will not be obtained again in the subsequent random number acquisition process.

[0128] Because the target tree structure occupies less memory. Compared with the related art, which uses hash key-value pairs in a hash table to delete the acquired random numbers, since each hash key pair in the related art is usually 300 bytes, taking 50 million random numbers as an example, it is necessary to create 50 million hash key-value pairs, which requires a total of about 14GB of memory size for storing the hash table. The embodiment of the present application greatly saves memory, thereby saving hardware costs.

[0129] To further avoid occupying memory space, the method further includes deleting the random number corresponding to the target identifier stored in the random number storage structure.

[0130] Please refer to Figure 15 Another embodiment of the present application provides a method for storing random numbers, the method comprising:

[0131] Step S410: constructing a tree structure based on the number of random numbers, where the tree structure includes a plurality of leaf nodes and a parent node corresponding to each leaf node.

[0132] The type of the tree structure can be arbitrary, such as an n-ary tree, where n is an integer greater than or equal to 2.

[0133] When the tree structure is an n-ary tree, the n-ary tree may be a complete n-ary tree or a full n-ary tree.

[0134] There are various ways to construct a tree structure based on the number of random numbers.

[0135] One approach is to construct a tree structure based on a preset correspondence and the number of random numbers. The preset correspondence stores multiple tree structure information and a range of random numbers corresponding to each piece of tree structure information. The tree structure information includes the tree structure type, the tree structure depth, and the number of random numbers corresponding to each leaf node. Specifically, the target tree structure information can be found from the preset correspondence using the number of random numbers, and the tree structure can be constructed based on the target tree structure information.

[0136] As another way, the number of random numbers, the maximum number of random numbers corresponding to each leaf node, and the type of binary tree may be used to determine the number of leaf nodes, and the tree structure may be constructed based on the number of leaf nodes and the type of tree structure.

[0137] Step S420: Store the random number information corresponding to each leaf node in the leaf node.

[0138] The random number information corresponding to each leaf node may be a random number, an identifier of a random number, the number of random numbers, or the number of identifiers of random numbers.

[0139] Step S430: Obtain a value according to the random number information stored in the leaf node corresponding to each parent node, and store the value in the parent node to obtain the target tree structure.

[0140] There are various ways to obtain a numerical value based on the random number information stored in the leaf node corresponding to each parent node. For example, the value can be obtained by summing the number of random numbers or the number of random number identifiers in the target leaf node corresponding to the parent node, performing weighted summing, or performing normalized summing.

[0141] The present application provides a method for storing random numbers, which constructs a tree structure based on the number of multiple random numbers, stores the information of the random number corresponding to each leaf node in the tree structure in the leaf node, and obtains a value based on the information of the random number stored in the leaf node corresponding to each parent node, and stores the value in the parent node to obtain a target tree structure. Since the value of the root node of the target tree structure can represent whether there is a leaf node corresponding to the random number in the target tree structure, when it is necessary to obtain a random number, the root node of the target tree structure is accessed, and when the value stored in the root node is not a set value (that is, it indicates that there is a leaf node corresponding to the random number in the target tree structure), the nodes of each layer are accessed layer by layer until the target leaf node storing the random number information is accessed, and the random number corresponding to the target leaf node is obtained. After using this embodiment to store random numbers, only one search is required to obtain the random number, thereby improving the efficiency of obtaining random numbers.

[0142] Please refer to Figure 16 , Figure 16 A flowchart of a random number storage method provided in another embodiment of the present application is shown, the method comprising:

[0143] Step S510: construct a bit storage structure based on the number of multiple random numbers, the bit storage structure includes multiple storage locations, each identifier corresponds to a storage location, each storage location stores a representation value, and the representation value is used to represent whether the storage location corresponds to the identifier.

[0144] Each random number has a unique identifier, and the identifier corresponding to each random number can be the sorting order of the storage locations corresponding to the random number in the random number storage structure. The number of storage locations included in the constructed bit storage structure can be the same as the number of random numbers, or can be greater than the number of random numbers.

[0145] It should be understood that when the number of storage locations included in the bit storage structure is greater than the number of random numbers, there are storage locations in the bit storage structure that do not have corresponding identifiers.

[0146] As an implementation manner, when the characterization value is a first set value, it indicates that the storage location where the characterization value is located has a corresponding identifier, and when the characterization value is a second set value, it indicates that the storage location where the characterization value is located has no corresponding identifier.

[0147] The first setting value and the second setting value mentioned above may be arbitrary values.

[0148] In order to save the storage space of the bit storage structure, the number of storage locations included in the constructed bit storage structure is the same as the number of identifiers. The memory space occupied by each storage location when storing data can be one bit, that is, the data stored in each storage location is a binary number of "0" or "1". As a way, it can be that when the characterization value is "1", it represents that there is a random number corresponding to the storage location where it is located, and when the characterization value is "0", it represents that there is no random number corresponding to the location where it is located. As another way, it can also be that when the characterization value is "0", it represents that there is a random number corresponding to the storage location where it is located, and when the characterization value is "1", it represents that there is no random number corresponding to the location where it is located.

[0149] Step S520: construct a tree structure according to the number of the plurality of storage locations, wherein each storage location corresponds to a leaf node in the tree structure.

[0150] There are different ways to build a tree structure based on the number of storage locations.

[0151] As one approach, a tree structure can be constructed based on a preset correspondence relationship and the number of storage locations. The preset correspondence relationship stores multiple tree structure information and a range of storage locations corresponding to each piece of tree structure information. The tree structure information includes the tree structure type, the tree structure depth, and the number of random numbers corresponding to each leaf node. Specifically, the target tree structure information can be found from the preset correspondence relationship using the number of random numbers, and the tree structure can be constructed based on the target tree structure information.

[0152] As another way, the number of leaf nodes can be determined based on the number of storage locations, the maximum number of storage locations corresponding to each leaf node, and the type of binary tree, and the tree structure can be constructed based on the number of leaf nodes and the type of tree structure.

[0153] Step S530: Obtain the number of storage locations storing the first set value from the storage locations corresponding to each leaf node, and store the number in the leaf node, where the first set value indicates that the storage location where the first set value is located has a corresponding identifier.

[0154] It should be noted that when a leaf node does not correspond to a storage location, the value stored corresponding to the leaf node is 0.

[0155] Step S540: Obtain a value based on the random number information stored in the leaf node corresponding to each parent node, and store the value in the parent node to obtain the target tree structure.

[0156] Please refer to Figure 17 , taking the number of random numbers as 50 as an example, when the number of random numbers is 50, the corresponding storage position of the corresponding bit storage structure is also 50, and the identifier of the random number is the sorting order of the storage position corresponding to the random number in the random number storage structure, and the representation value stored in each storage position is "1".

[0157] When it is determined that the type of tree structure is a full binary tree and the maximum number of storage locations corresponding to the leaf nodes of each binary tree is 4, the 50 storage locations can be divided into 13 groups of storage locations with 4 storage locations corresponding to each group, and the 13th group of storage locations includes only two storage locations. The number of leaf nodes included in the corresponding full binary tree is 16, and the nth leaf node on the left of the target tree structure corresponds to the nth group of storage locations. The number of storage locations corresponding to each leaf node with a characterization value of "1" is used as the information of the random number stored corresponding to each leaf node. That is, when n is 0 to 12, the corresponding stored random number information is the number of random number identifiers 4, when n is 13, the corresponding stored random number information is the number of random number identifiers 2, and when n is 13 to 16, the corresponding stored random number information is the number of random number identifiers 0. The value stored in each parent node is the sum of the number of random number identifiers stored in the leaf nodes corresponding to the parent node.

[0158] The present application provides a method for storing random numbers. The method constructs a bit storage structure based on the number of multiple random numbers and a tree structure based on the storage position of the bit storage structure. The random number information corresponding to each leaf node in the tree structure is stored in the leaf node. A value is obtained based on the random number information stored in the leaf node corresponding to each parent node, and the value is stored in the parent node to obtain a target tree structure. When a random number needs to be obtained, the root node of the target tree structure is accessed. When the value stored in the root node is not a set value, the nodes of each layer are accessed layer by layer until the target leaf node storing the random number information is accessed. The storage location corresponding to the target leaf node is obtained, and the target storage location is determined from the storage location. The identifier corresponding to the target storage location is obtained, and the corresponding random number is obtained using the identifier. After using the random number storage method of this embodiment, the random number can be obtained with only one search, thereby greatly improving the efficiency of obtaining random numbers.

[0159] See also Figure 18 , Figure 18 A flowchart of a random number storage method provided in another embodiment of the present application is shown, and the method includes:

[0160] Step S610: constructing a random number storage structure based on the number of the multiple random numbers, the random number storage structure including multiple storage locations, each random number is stored in a storage location, and the order of the storage location storing the random number in the random number storage structure is the identifier corresponding to the random number.

[0161] The number of storage locations included in the random number storage structure may be the same as or greater than the number of random numbers.

[0162] It should be understood that when the number of storage locations included in the random number storage structure is greater than the number of random numbers, there are storage locations that do not store any random numbers.

[0163] Step S620: constructing a tree structure according to the number of the plurality of storage locations, wherein each leaf node in the tree structure corresponds to at least one storage location in the random number storage structure.

[0164] There are various ways to construct the tree structure depending on the number of storage locations.

[0165] As one approach, a tree structure can be constructed based on a preset correspondence relationship and the number of storage locations. The preset correspondence relationship stores multiple tree structure information and a range of storage locations corresponding to each piece of tree structure information. The tree structure information includes the tree structure type, the tree structure depth, and the number of random numbers corresponding to each leaf node. Specifically, the target tree structure information can be found from the preset correspondence relationship using the number of random numbers, and the tree structure can be constructed based on the target tree structure information.

[0166] As another way, the number of leaf nodes can be determined based on the number of storage locations, the maximum number of storage locations corresponding to each leaf node, and the type of binary tree, and the tree structure can be constructed based on the number of leaf nodes and the type of tree structure.

[0167] Step S630: Store the identifier of the random number stored in at least one storage location corresponding to each leaf node in the leaf node.

[0168] Step S640: Obtain a value according to the random number information stored in the leaf node corresponding to each parent node, and store the value in the parent node to obtain the target tree structure.

[0169] Please refer to Figure 19 , taking the number of random numbers as 50 as an example, when the number of random numbers is 50, the corresponding storage position of the random number storage structure is also 50, and the identifier of the random number is the sorting order of the storage position corresponding to the random number in the random number storage structure, and each storage position is used to store a random number.

[0170] When it is determined that the type of tree structure is a full binary tree and the maximum number of storage locations corresponding to the leaf nodes of each binary tree is 4, the 50 storage locations can be divided into 13 groups of storage locations with 4 storage locations corresponding to each group, and the 13th group of storage locations includes only two storage locations. The number of leaf nodes included in the corresponding full binary tree is 16, and the nth leaf node on the left in the target tree structure corresponds to the nth group of storage locations. The identifier of the storage location where the random number is stored in a group of storage locations corresponding to each leaf node is used as the information of the random number stored corresponding to each leaf node. The numerical value stored in each parent node is the number of identifiers of the random numbers stored in the leaf node corresponding to the parent node.

[0171] The present application provides a method for storing random numbers. The method constructs a random number storage structure based on the number of multiple random numbers and a tree structure based on the storage position of a bit storage structure. The random number information corresponding to each leaf node in the tree structure is stored in the leaf node. A numerical value is obtained based on the random number information stored in the leaf node corresponding to each parent node, and the numerical value is stored in the parent node to obtain a target tree structure. Thus, when a random number needs to be obtained, the root node of the target tree structure is accessed. When the numerical value stored in the root node is not a set numerical value, the nodes of each layer are accessed layer by layer until the target leaf node storing the random number information is accessed. The target identifier stored in the target leaf node is obtained, and the random number corresponding to the target identifier is obtained. After using the random number storage method of this embodiment, the random number can be obtained with only one search, thereby greatly improving the efficiency of obtaining random numbers.

[0172] See also Figure 20 , Figure 20 FIG. 7 shows a connection block diagram of a random number acquisition device 700 provided in another embodiment of the present application. The device 700 includes:

[0173] The access module 710 is used to access the root node of the target tree structure.

[0174] The target tree structure includes a root node and N leaf nodes, where N is an integer greater than 1. Each leaf node is used to store the corresponding random number information, and the parent node corresponding to the leaf node is used to store a numerical value, which is obtained based on the random number information stored in the leaf node corresponding to the parent node.

[0175] The first acquisition module 720, when the value stored in the root node is not the set value, accesses the nodes of each layer layer by layer until the target leaf node storing the random number information is accessed, and obtains the random number corresponding to the target leaf node.

[0176] As a method, the first acquisition module 720 is also used to randomly access nodes in each layer layer by layer.

[0177] As another approach, the first acquisition module 720 is further configured to obtain the probability of accessing each child node based on the data stored in the child node connected to the root node. When the child node is a leaf node, the data stored in the child node is a random number; when the child node is not a leaf node, the data stored in the child node is a numerical value. A target child node is selected based on the probability corresponding to each child node, and the target child node corresponds to a random number. When the target child node is not a leaf node, the target child node is used as the new root node until the selected target child node is a leaf node, at which point the random number corresponding to the target leaf node is obtained.

[0178] As a way, Figure 21 As shown, the first acquisition module 720 includes:

[0179] The first search submodule 721 is used to search a storage location corresponding to the target leaf node from the bit storage structure as the target storage location.

[0180] The bit storage structure includes multiple storage locations, each of which stores a representation value, which is used to represent whether the storage location in which it is located corresponds to an identifier, and each leaf node corresponds to at least one storage location in the bit storage structure;

[0181] A first acquisition submodule 722 is configured to acquire a target identifier corresponding to the target storage location when the representation value stored in the target storage location is a first set value, wherein the first set value indicates that the target storage location has an identifier.

[0182] The second acquisition submodule 723 is configured to acquire a random number corresponding to the target identifier.

[0183] In this manner, the apparatus 700 further includes:

[0184] A first adjustment module 730 is configured to adjust the representation value stored in the target storage location from a first set value to a second set value, where the second set value is used to represent that the target storage location does not correspond to an identifier;

[0185] The second acquisition module 740 acquires the number of storage locations storing the first set value in at least one storage location corresponding to the target leaf node, and uses the number as information about the random number stored in the target leaf node;

[0186] The first updating module 750 is configured to update the values ​​stored in the parent nodes corresponding to the target leaf node in the target tree structure according to the random number information stored in the target leaf node.

[0187] As another way, Figure 22 As shown, the first acquisition module 720 includes:

[0188] The third acquisition submodule 725 is configured to select a target identifier from the identifiers stored in the target leaf node.

[0189] A second search submodule 726 is configured to search a target storage location corresponding to a target identifier from a random number storage structure, wherein the random number storage structure includes a plurality of storage locations for storing random numbers, and each identifier corresponds to a random number storage location;

[0190] The fourth acquisition submodule 727 is configured to acquire the random number stored in the target storage location.

[0191] In this manner, the apparatus 700 further includes:

[0192] The second adjustment module 780 is configured to delete the target identifier stored in the target leaf node to obtain an identifier of an adjusted random number;

[0193] The second updating module 790 is configured to update the values ​​stored in the parent nodes corresponding to the target leaf node in the target tree structure according to the identifier of the adjusted random number stored in the target leaf node.

[0194] In this manner, the apparatus 700 further includes: a deletion module, configured to delete the random number stored in the random number storage structure.

[0195] The present application provides a random number acquisition device 700, which accesses the root node of a target tree structure. When the value stored in the root node is not a set value, it confirms that the target tree structure corresponds to a random number, and after accessing the nodes of the target tree structure layer by layer, it can obtain the target leaf node corresponding to the random number that is finally accessed, and obtain the random number corresponding to the target leaf node. Compared with the related art that may require multiple visits to the random number storage structure to obtain the random number, the present application greatly improves the efficiency of obtaining random numbers.

[0196] See also Figure 23 , Figure 23 FIG. 8 is a block diagram showing a connection of a random number storage device 800 provided in another embodiment of the present application. The device 800 includes:

[0197] The construction module 810 is configured to construct a tree structure based on the number of random numbers.

[0198] The tree structure includes multiple leaf nodes and parent nodes corresponding to each leaf node, and each leaf node corresponds to at least one random number.

[0199] The first storage module 820 is configured to store information of a random number corresponding to each leaf node in the leaf node.

[0200] The second storage module 830 is used to obtain a value according to the random number information stored in the leaf node corresponding to each parent node, and store the value in the parent node to obtain the target tree structure.

[0201] As one approach, building block 810 includes:

[0202] The first construction submodule is used to construct a bit storage structure based on the number of multiple random numbers.

[0203] The bit storage structure includes multiple storage locations, each identifier corresponds to a storage location, and each storage location stores a representation value, which is used to represent whether the storage location where it is located corresponds to an identifier.

[0204] The second construction submodule is used to construct a tree structure according to the number of the plurality of storage locations, each storage location corresponding to a leaf node in the tree structure.

[0205] The first storage module 820 is also used to obtain the number of storage locations storing the first set value from the storage locations corresponding to each leaf node, and store the number in the leaf node. The first set value represents that the storage location where it is located has an identifier.

[0206] As another approach, building block 810 includes:

[0207] A third construction submodule is configured to construct a random number storage structure based on the number of the multiple random numbers, the random number storage structure including multiple storage locations, each random number being stored in one storage location, and the order of the storage locations storing the random numbers in the random number storage structure being identifiers corresponding to the random numbers;

[0208] The fourth construction submodule is used to construct a tree structure according to the number of multiple storage locations, and each storage location in the random number storage structure corresponds to a leaf node in the tree structure.

[0209] The first storage module 820 is further configured to store the identifier of the random number stored in the storage location corresponding to each leaf node in the leaf node.

[0210] The present application provides a random number storage device 800, which constructs a random number storage structure based on the number of multiple random numbers and a tree structure based on the storage position of the bit storage structure, stores the random number information corresponding to each leaf node in the tree structure in the leaf node, and obtains a value based on the random number information stored in the leaf node corresponding to each parent node, and stores the value in the parent node to obtain a target tree structure. Therefore, when a random number needs to be obtained, the root node of the target tree structure is accessed, and when the value stored in the root node is not the set value, the nodes of each layer are accessed layer by layer until the target leaf node storing the random number information is accessed, the target identifier stored in the target leaf node is obtained, and the random number corresponding to the target identifier is obtained. After using the random number storage method of this embodiment, the random number can be obtained with only one search, thereby greatly improving the efficiency of obtaining random numbers.

[0211] It should be noted that the device embodiment in this application corresponds to the aforementioned method embodiment. The specific principles in the device embodiment can be found in the contents of the aforementioned method embodiment and will not be repeated here.

[0212] The following will be combined Figure 24 An electronic device provided by this application is described.

[0213] See also Figure 24 Based on the random number acquisition method and random number storage method provided in the above embodiments, the present application also provides another electronic device 100 including a processor 102 that can execute the above methods. The electronic device 100 can be a server or a terminal device, and the terminal device can be a smart phone, tablet computer, computer or portable computer. As a way, the electronic device 100 can be as follows Figure 1 The game server 10 or the game client 20 in the game interaction system shown.

[0214] The electronic device 100 further includes a memory 104 . The memory 104 stores a program capable of executing the contents of the aforementioned embodiments, and the processor 102 can execute the program stored in the memory 104 .

[0215] The processor 102 may include one or more cores for processing data and a message matrix unit. The processor 102 utilizes various interfaces and circuits to connect various components within the electronic device 100. It executes instructions, programs, code sets, or instruction sets stored in the memory 104, and accesses data stored in the memory 104 to perform various functions and process data within the electronic device 100. Optionally, the processor 102 may be implemented using at least one of the following hardware forms: a digital signal processing (DSP), a field-programmable gate array (FPGA), or a programmable logic array (PLA). The processor 102 may integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing display content; and the modem handles wireless communications. It is understood that the modem may not be integrated into the processor 102 and may be implemented separately via a communication chip.

[0216] The memory 104 may include a random access memory (RAM) or a read-only memory (ROM). The memory 104 may be used to store instructions, programs, codes, code sets, or instruction sets. The memory 104 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (e.g., instructions for a user to obtain a random number), instructions for implementing the various method embodiments described below, and the like. The data storage area may also store data (e.g., random numbers) created by the terminal 100 during use.

[0217] The electronic device 100 may also include a network module and a screen. The network module is used to receive and transmit electromagnetic waves, realize the mutual conversion between electromagnetic waves and electrical signals, and thus communicate with a communication network or other devices, such as communicating with an audio playback device. The network module may include various existing circuit components for performing these functions, such as antennas, radio frequency transceivers, digital signal processors, encryption / decryption chips, user identity modules (SIM) cards, memories, and the like. The network module can communicate with various networks such as the Internet, corporate intranets, wireless networks, or communicate with other devices via wireless networks. The above-mentioned wireless networks may include cellular telephone networks, wireless local area networks, or metropolitan area networks. The screen can display interface content and perform data interaction.

[0218] Please refer to Figure 25 , which shows a block diagram of a computer-readable storage medium provided in an embodiment of the present application. The computer-readable medium 900 stores program code, which can be called by a processor to execute the method described in the above method embodiment.

[0219] The computer-readable storage medium 900 can be an electronic memory such as a flash memory, an EEPROM (Electrically Erasable Programmable Read-Only Memory), an EPROM, a hard disk, or a ROM. Alternatively, the computer-readable storage medium 900 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 900 has storage space for program code 910 for executing any of the method steps in the above method. These program codes can be read from or written to one or more computer program products. The program code 910 can be compressed, for example, in a suitable form.

[0220] The present application also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods described in the various optional implementations described above.

[0221] In summary, the present application provides a method for obtaining a random number, a storage method, an apparatus, an electronic device and a medium. In the method, the root node of the target tree structure is accessed. When the value stored in the root node is not the set value, the nodes of each layer are accessed layer by layer until the target leaf node storing the random number information is accessed, and the random number corresponding to the target leaf node is obtained. When the value stored in the root node is not the set value, it is confirmed that the target tree structure corresponds to the random number, and after accessing the nodes of the target tree structure layer by layer, the target leaf node corresponding to the random number that is finally accessed can be obtained, and the random number corresponding to the target leaf node can be obtained. Compared with the related art, which may require multiple visits to the random number storage structure to obtain the random number, the present application greatly improves the efficiency of obtaining random numbers.

[0222] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for obtaining a random number, characterized in that: include: Accessing a root node of a target tree structure, the target tree structure comprising the root node and N leaf nodes, where N is an integer greater than 1, each leaf node being configured to store information about a corresponding random number, and a parent node corresponding to the leaf node being configured to store a value obtained based on the random number information stored in the leaf node corresponding to the parent node; When the value stored in the root node is not a set value, access each layer of nodes layer by layer until a target leaf node storing random number information is accessed, and a random number corresponding to the target leaf node is obtained, wherein each random number corresponds to an identifier, and the value stored in each parent node is obtained according to the number of identifiers corresponding to the leaf nodes corresponding to the parent node; If the target tree structure is constructed based on a bit storage structure, obtaining a random number corresponding to the target leaf node includes: Searching a storage location corresponding to the target leaf node from a bit storage structure as the target storage location, wherein the bit storage structure includes a plurality of storage locations, each of the storage locations stores a characterization value, the characterization value being used to characterize whether the storage location in which the storage location is located corresponds to an identifier, and each leaf node corresponds to at least one storage location in the bit storage structure; When the representation value stored in the target storage location is a first set value, obtaining a target identifier corresponding to the target storage location, wherein the first set value represents that the target storage location has an identifier; Obtain a random number corresponding to the target identifier.

2. The method according to claim 1, characterized in that After obtaining the random number corresponding to the target identifier, the method further includes: Adjusting the representation value stored in the target storage location from a first set value to a second set value, wherein the second set value is used to represent that the target storage location does not correspond to an identifier; Obtaining the number of storage locations storing a first set value in at least one storage location corresponding to the target leaf node, and using the number as information about the random number stored in the target leaf node; According to the random number information stored in the target leaf node, the values ​​stored in each parent node corresponding to the target leaf node in the target tree structure are updated.

3. The method according to claim 1, characterized in that If the target tree structure is constructed based on a random number storage structure, obtaining the random number corresponding to the target leaf node includes: Select a target identifier from the identifiers stored in the target leaf node; searching a target storage location corresponding to the target identifier from a random number storage structure, wherein the random number storage structure includes a plurality of storage locations for storing random numbers, each identifier corresponding to a random number storage location; Obtain the random number stored in the target storage location.

4. The method according to claim 3, characterized in that After obtaining the random number corresponding to the target identifier, the method further includes: Deleting the target identifier stored in the target leaf node to obtain an identifier of an adjusted random number; According to the identifier of the adjusted random number stored in the target leaf node, the numerical values ​​stored in each parent node corresponding to the target leaf node in the target tree structure are updated.

5. The method according to claim 3, characterized in that After obtaining the random number corresponding to the target leaf node, the method further includes: Delete the random number corresponding to the target leaf node stored in the random number storage structure.

6. The method according to any one of claims 1 to 5, characterized in that The value stored in each parent node is the sum of the numbers of identifiers corresponding to the leaf nodes corresponding to the parent node.

7. The method according to claim 1, characterized in that The step of accessing nodes at each layer layer by layer includes: Obtain the probability of accessing each child node based on the data stored in the child node connected to the root node, where if the child node is a leaf node, the data stored in the child node is a random number; if the child node is not a leaf node, the data stored in the child node is a numerical value; A target child node is selected according to the probability corresponding to each child node, and the target child node corresponds to a random number; When the target child node is not a leaf node, the target child node is used as a new root node, and the step of obtaining the probability of accessing each child node based on the data stored in the multiple child nodes connected to the root node is returned, until the selected target child node is a leaf node, and a random number corresponding to the target leaf node is obtained.

8. A method for storing random numbers, characterized in that: include: Constructing a tree structure based on the number of random numbers, the tree structure including a plurality of leaf nodes and a parent node corresponding to each leaf node, each random number corresponding to a leaf node, and each random number corresponding to an identifier; The random number information corresponding to each leaf node is stored in the leaf node; Obtain a value based on the random number information stored in the leaf node corresponding to each parent node, and store the value in the parent node to obtain the target tree structure; If the tree structure is constructed based on a bit storage structure, the step of constructing the tree structure based on the number of random numbers includes: Constructing a bit storage structure based on the number of random numbers, the bit storage structure including multiple storage locations, each identifier corresponding to a storage location, each storage location storing a characterization value, the characterization value being used to indicate whether the storage location corresponding to the identifier is located; Constructing a tree structure according to the number of the plurality of storage locations, each of the storage locations corresponding to a leaf node in the tree structure; The step of storing information of a random number corresponding to each leaf node in the leaf node includes: The number of storage locations storing the first setting value is obtained from the storage location corresponding to each leaf node, and the number is stored in the leaf node. The first setting value represents that the storage location where it is located has a corresponding identifier.

9. The method according to claim 8, characterized in that If the tree structure is constructed based on a random number storage structure, the step of constructing the tree structure based on the number of random numbers includes: Constructing a random number storage structure based on the number of the plurality of random numbers, the random number storage structure comprising a plurality of storage locations, each of the random numbers being stored in a storage location, and the order of the storage locations storing the random numbers in the random number storage structure being an identifier corresponding to the random number; Constructing a tree structure according to the number of the plurality of storage locations, wherein each storage location in the random number storage structure corresponds to a leaf node in the tree structure; The step of storing information of a random number corresponding to each leaf node in the leaf node includes: The identifier of the random number stored in the storage location corresponding to each leaf node is stored in the leaf node.

10. A random number acquisition device, characterized in that: include: An access module, configured to access a root node of a target tree structure, wherein the target tree structure includes a root node and N leaf nodes, where N is an integer greater than 1, each leaf node being configured to store information of a corresponding random number, and a parent node corresponding to the leaf node being configured to store a numerical value, the numerical value being obtained based on the random number information stored in the leaf node corresponding to the parent node, wherein each random number is associated with an identifier, and the numerical value stored in each parent node is obtained based on the number of identifiers corresponding to the leaf nodes corresponding to the parent node; An acquisition module is used to, when the value stored in the root node is not a set value, access the nodes of each layer layer by layer until the target leaf node storing the random number information is accessed and the target tree structure is constructed based on the bit storage structure, search the bit storage structure for a storage location corresponding to the target leaf node as the target storage location, the bit storage structure includes a plurality of storage locations, each of the storage locations stores a representation value, the representation value is used to represent whether the storage location corresponds to an identifier, and each leaf node corresponds to at least one storage location in the bit storage structure; when the representation value stored in the target storage location is a first set value, obtain the target identifier corresponding to the target storage location, the first set value represents that the target storage location corresponds to an identifier; obtain the random number corresponding to the target identifier.

11. The device according to claim 10, characterized in that The acquisition module is further configured to select a target identifier from identifiers stored in a target leaf node when the target tree structure is constructed based on a random number storage structure; Searching a target storage location corresponding to the target identifier from a random number storage structure, the random number storage structure including a plurality of storage locations for storing random numbers, each identifier corresponding to a random number storage location; and obtaining the random number stored in the target storage location.

12. A random number storage device, characterized in that: include: A construction module, configured to construct a tree structure based on the number of random numbers, the tree structure comprising a plurality of leaf nodes and a parent node corresponding to each of the leaf nodes, each leaf node corresponding to at least one random number, and each random number corresponding to an identifier; The construction module is further configured to, when the tree structure is constructed based on the bit storage structure, construct the bit storage structure based on the number of multiple random numbers, the bit storage structure including multiple storage locations, each identifier corresponding to a storage location, each storage location storing a characterization value, the characterization value being used to characterize whether the storage location in which it is located corresponds to the identifier; construct a tree structure based on the number of the multiple storage locations, each storage location corresponding to a leaf node in the tree structure; A first storage module is configured to store the identifier of the random number stored in the storage location corresponding to each leaf node in the leaf node; The second storage module is used to obtain a value according to the random number information stored in the leaf node corresponding to each parent node, and store the value in the parent node to obtain the target tree structure.

13. The device according to claim 12, characterized in that The construction module is further configured to construct the random number storage structure based on the number of random numbers when the tree structure is constructed based on the random number storage structure, wherein the random number storage structure includes a plurality of storage locations, each random number is stored in a storage location, and the order of the storage location storing the random number in the random number storage structure is an identifier corresponding to the random number; Constructing a tree structure according to the number of the plurality of storage locations, wherein each storage location in the random number storage structure corresponds to a leaf node in the tree structure; The first storage module is used to store the identifier of the random number stored in the storage location corresponding to each leaf node in the leaf node.

14. An electronic device, characterized in that: The method comprises a processor and a memory; one or more programs are stored in the memory and configured to be executed by the processor to implement the method according to any one of claims 1 to 7 or 8 to 9.

15. A computer-readable storage medium, characterized in that The computer-readable storage medium stores program code, wherein when the program code is executed by a processor, the method according to any one of claims 1 to 7 or 8 to 9 is executed.

Citation Information

Patent Citations

  • Method for searching a tree structure

    US20100082664A1