True random number generation method and device, electronic equipment and readable storage medium
Patent Information
- Application Number
- CN202211596798.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-12
- Publication Date
- 2026-10-20
- Estimated Expiration
- 2042-12-12
AI Technical Summary
现有技术中的随机数产生算法无法产生大量真随机数
[0032]上述本申请提供的真随机数生成方法、装置、电子设备及可读存储介质,利用伪随机数产生算法生成伪随机数序列,所述伪随机数序列包括多个伪随机数;确定所述伪随机数序列的产生延迟时间,其中,所述产生延迟时间为生成所述伪随机数序列的首个伪随机数到终个伪随机数所需时间;根据所述产生延迟时间确定各伪随机数的偏移量;根据各伪随机数及其偏移量分别生成一个真随机数。这样,利用生成伪随机数序列的产生时间延迟时间作为各伪随机数的偏移量,根据各伪随机数及其偏移量得到多个真随机数,在短时间内产生大量真随机数,提高生成真随机数的速度。
Smart Images

Figure CN115878077B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a method, apparatus, electronic device, and readable storage medium for generating true random numbers. Background Technology
[0002] Currently, commonly used random number generation algorithms include the linear congruential method. The random values generated by the linear congruential method are pseudo-random values, and the resulting sequences are periodic sequences. Existing random number generation algorithms cannot generate a large number of truly random numbers. Summary of the Invention
[0003] To address the aforementioned technical problems, embodiments of this application provide a true random number generation method, apparatus, electronic device, and readable storage medium.
[0004] In a first aspect, embodiments of this application provide a method for generating true random numbers, the method comprising:
[0005] A pseudo-random number sequence is generated using a pseudo-random number generation algorithm, wherein the pseudo-random number sequence includes multiple pseudo-random numbers;
[0006] Determine the generation delay time of the pseudo-random number sequence, wherein the generation delay time is the time required to generate the first pseudo-random number to the last pseudo-random number in the pseudo-random number sequence;
[0007] The offset of each pseudo-random number is determined based on the generation delay time;
[0008] Generate a true random number based on each pseudo-random number and its offset.
[0009] In one embodiment, determining the generation delay time of the pseudo-random number sequence includes:
[0010] Obtain the CUP timestamp of the first pseudo-random number and the CUP timestamp of the last pseudo-random number;
[0011] The time difference between the CUP timestamp of the first pseudo-random number and the CUP timestamp of the last pseudo-random number is determined as the generation delay time of the pseudo-random number sequence.
[0012] In one embodiment, generating a true random number based on each pseudo-random number and its offset includes:
[0013] The sum of each pseudo-random number and its offset is determined as a true random number.
[0014] In one embodiment, generating a pseudo-random number sequence using a pseudo-random number generation algorithm includes:
[0015] The pseudo-random number generation algorithm is used to generate the current round of pseudo-random number sequence based on the previous round of pseudo-random number sequence, multiple initial constant sequences, and the previous round generation delay time. The previous round of pseudo-random number sequence includes multiple pseudo-random numbers generated by the pseudo-random number generation algorithm in the previous round, and each of the initial constant sequences includes multiple initial constants.
[0016] In one embodiment, the pseudo-random number generation algorithm generates the current round's pseudo-random number sequence based on the previous round's pseudo-random number sequence, multiple initial constant sequences, and the previous round's generation delay time. The previous round's pseudo-random number sequence includes multiple pseudo-random numbers generated by the pseudo-random number generation algorithm in the previous round. Each of the initial constant sequences includes multiple initial constants, including:
[0017] The j-th pseudo-random number in the current round of pseudo-random number sequence is determined according to the following formula;
[0018] aj = Aiai + Bi + TmodMi;
[0019] Among them, A i B represents the i-th initial constant in the first initial constant sequence. i M represents the i-th initial constant in the second initial constant sequence. i Let represent the i-th initial constant in the third initial constant sequence, T represent the delay time generated in the previous round, and a i Let a represent the i-th pseudo-random number in the previous round of pseudo-random number sequence. j Let represent the j-th pseudo-random number in the current round of pseudo-random number sequence, where mod represents the modulo operation, and j = i.
[0020] In one embodiment, generating a pseudo-random number sequence using a pseudo-random number generation algorithm includes:
[0021] Set the initial generation delay time, the initial random number sequence, and multiple initial constant sequences;
[0022] The pseudo-random number generation algorithm is used to determine the first round of pseudo-random number sequence based on the initial generation delay time, the initial random number sequence, and multiple initial constant sequences.
[0023] In one embodiment, generating a pseudo-random number sequence using a pseudo-random number generation algorithm includes:
[0024] The pseudo-random number sequence is generated by controlling the pseudo-random number generation algorithm through the AVX instruction set.
[0025] Secondly, embodiments of this application provide a true random number generation apparatus, the apparatus comprising:
[0026] The first generation module is used to generate a pseudo-random number sequence using a pseudo-random number generation algorithm, wherein the pseudo-random number sequence includes multiple pseudo-random numbers;
[0027] The first determining module is used to determine the generation delay time of the pseudo-random number sequence, wherein the generation delay time is the time required to generate the first pseudo-random number to the last pseudo-random number of the pseudo-random number sequence;
[0028] The second determining module is used to determine the offset of each pseudo-random number based on the generation delay time;
[0029] The second generation module is used to generate a true random number based on each pseudo-random number and its offset.
[0030] Thirdly, embodiments of this application provide an electronic device, including a memory and a processor, wherein the memory is used to store a computer program, and the computer program executes the true random number generation method provided in the first aspect when the processor is running.
[0031] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when run on a processor, executes the true random number generation method provided in the first aspect.
[0032] The true random number generation method, apparatus, electronic device, and readable storage medium provided in this application utilize a pseudo-random number generation algorithm to generate a pseudo-random number sequence, wherein the pseudo-random number sequence includes multiple pseudo-random numbers; determine the generation delay time of the pseudo-random number sequence, wherein the generation delay time is the time required to generate the first pseudo-random number to the last pseudo-random number in the pseudo-random number sequence; determine the offset of each pseudo-random number based on the generation delay time; and generate a true random number based on each pseudo-random number and its offset. In this way, by using the generation delay time of the pseudo-random number sequence as the offset of each pseudo-random number, multiple true random numbers are obtained based on each pseudo-random number and its offset, generating a large number of true random numbers in a short time, thus improving the speed of true random number generation. Attached Figure Description
[0033] To more clearly illustrate the technical solutions of this application, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of this application and should not be considered as a limitation on the scope of protection of this application. In the various drawings, similar components are numbered similarly.
[0034] Figure 1 A flowchart of a true random number generation method provided in an embodiment of this application is shown;
[0035] Figure 2A schematic diagram of the structure of a true random number generation device provided in an embodiment of this application is shown.
[0036] Icons: 200 - True random number generation device; 201 - First generation module; 202 - First determination module; 203 - Second determination module; 204 - Second generation module. Detailed Implementation
[0037] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0038] The components of the embodiments of this application described and illustrated in the accompanying drawings can be arranged and designed in a variety of different configurations. Therefore, the following detailed description of the embodiments of this application provided in the drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0039] In the following, the terms “comprising,” “having,” and their cognates, which may be used in various embodiments of this application, are intended only to indicate a particular feature, number, step, operation, element, component, or combination thereof, and should not be construed as excluding, firstly, the presence of one or more other features, numbers, steps, operations, elements, components, or combinations thereof, or adding the possibility of one or more features, numbers, steps, operations, elements, components, or combinations thereof.
[0040] Furthermore, the terms "first," "second," and "third" are used only to distinguish descriptions and should not be interpreted as indicating or implying relative importance.
[0041] Unless otherwise specified, all terms used herein (including technical and scientific terms) shall have the same meaning as commonly understood by one of ordinary skill in the art to which the various embodiments of this application pertain. Terms (such as those defined in commonly used dictionaries) shall be interpreted as having the same meaning as in their contextual meaning in the relevant technical field and shall not be construed as having an idealized or overly formal meaning, unless clearly defined in the various embodiments of this application.
[0042] Currently, commonly used random number generation algorithms include the linear congruential method, which generates pseudo-random numbers based on the following formula:
[0043] a n+1 =A×a n +BmodM;
[0044] The above formula recursively generates a sequence as random values, a n+1 Let a represent the (n+1)th random value. n Let A, B, and M represent the nth random value. A, B, and M are three initial constants. If A, B, and M are known, and the currently generated random value is known, the next random value can be easily calculated. Therefore, the random values generated by the linear congruential method are pseudo-random values. Furthermore, the above formula also shows that the generated sequence is a periodic sequence with a maximum period of M. Existing random number generation algorithms cannot generate a large number of truly random numbers.
[0045] Example 1
[0046] This application provides a method for generating true random numbers.
[0047] See Figure 1 The true random number generation method provided in this application includes steps S101-S104, and each step is described below.
[0048] Step S101: Generate a pseudo-random number sequence using a pseudo-random number generation algorithm. The pseudo-random number sequence includes multiple pseudo-random numbers.
[0049] In one embodiment, step S101 includes:
[0050] The pseudo-random number generation algorithm is used to generate the current round of pseudo-random number sequence based on the previous round of pseudo-random number sequence, multiple initial constant sequences, and the previous round generation delay time. The previous round of pseudo-random number sequence includes multiple pseudo-random numbers generated by the pseudo-random number generation algorithm in the previous round, and each of the initial constant sequences includes multiple initial constants.
[0051] Multiple initial constant sequences can be 2, 3, ..., N, where N is a positive integer determined according to the actual situation and is not limited here.
[0052] In this embodiment, to maximize the randomness of the pseudo-random number sequence, a pseudo-random number generation algorithm can be used for multiple rounds of computation. Each round of computation yields a corresponding pseudo-random number sequence, and a pseudo-random number sequence with better randomness can be used for subsequent calculations. The current round's pseudo-random number sequence is based on the previous round's pseudo-random number sequence, multiple initial constant sequences, and multiple generation delay times from the previous round.
[0053] In one embodiment, the pseudo-random number generation algorithm generates the current round's pseudo-random number sequence based on the previous round's pseudo-random number sequence, multiple initial constant sequences, and the previous round's generation delay time. The previous round's pseudo-random number sequence includes multiple pseudo-random numbers generated by the pseudo-random number generation algorithm in the previous round. Each of the initial constant sequences includes multiple initial constants, including:
[0054] The j-th pseudo-random number in the current round of pseudo-random number sequence is determined according to the following formula;
[0055] aj = Aiai + Bi + TmodMi;
[0056] Among them, A i B represents the i-th initial constant in the first initial constant sequence. i M represents the i-th initial constant in the second initial constant sequence. i Let represent the i-th initial constant in the third initial constant sequence, T represent the delay time generated in the previous round, and a i Let a represent the i-th pseudo-random number in the previous round of pseudo-random number sequence. j Let represent the j-th pseudo-random number in the current round of pseudo-random number sequence, where mod represents the modulo operation, and j = i.
[0057] As an example, the first, second, and third initial constant sequences can be represented by the following matrices:
[0058]
[0059] Among them, A1 to A N This indicates that the first initial constant sequence includes N initial constants, B1 to B... N This indicates that the second initial constant sequence includes N initial constants, M1 to M... N This indicates that the third initial constant sequence includes N initial constants, and correspondingly, N pseudo-random numbers can be calculated. For example, N can be 4096, or other set values; there are no restrictions here.
[0060] In one embodiment, step S101 includes:
[0061] Set the initial generation delay time, the initial random number sequence, and multiple initial constant sequences;
[0062] The pseudo-random number generation algorithm is used to determine the first round of pseudo-random number sequence based on the initial generation delay time, the initial random number sequence, and multiple initial constant sequences.
[0063] As an example, the initial generation delay time can be set to 0, and multiple pseudo-random numbers can be randomly generated to form an initial random number sequence. These multiple initial constant sequences are pre-set first, second, and third initial constant sequences. For example, A1 to A... N Represents the first initial constant sequence, B1 to B... N Denotes the second initial constant sequence, M1 to M... NThe j-th pseudo-random number in the first round of pseudo-random number sequence can be determined using the following formula, representing the third initial constant sequence.
[0064] a j =A i a i +B i +TmodM i ;
[0065] A i B represents the i-th initial constant in the first initial constant sequence. i M represents the i-th initial constant in the second initial constant sequence. i This represents the i-th initial constant in the third initial constant sequence, where T is 0, and a i Let a represent the i-th pseudo-random number in the initial random number sequence. j This represents the j-th pseudo-random number in the current round's pseudo-random number sequence. `mod` represents the modulo operation, and j = i, 1 ≤ i ≤ N, 1 ≤ j ≤ N. For example, N can be 4096, or any other value; there are no restrictions here.
[0066] In one embodiment, step S101 includes:
[0067] The pseudo-random number sequence is generated by controlling the pseudo-random number generation algorithm through the AVX instruction set.
[0068] In this embodiment, the Advanced Vector Extensions (AVX) instruction set is a type of Single Instruction Multiple Data (SIMD) instruction set. Utilizing the AVX instruction set, eight instructions are grouped together, allowing a single instruction to update eight pseudo-random numbers, reducing the number of loops and thus accelerating the process. This enables SIMD operations, allowing the generation of a large number of pseudo-random numbers in a short time, improving the pseudo-random number generation time, and effectively shortening the time required to generate a large number of truly random numbers.
[0069] Step S102: Determine the generation delay time of the pseudo-random number sequence, wherein the generation delay time is the time required to generate the first pseudo-random number to the last pseudo-random number of the pseudo-random number sequence.
[0070] In this embodiment, after one round of computation using the pseudo-random number generation algorithm, a pseudo-random number sequence can be generated. Each round's pseudo-random number sequence includes multiple pseudo-random numbers. Since the processing speed of the Central Processing Unit (CPU) is unpredictable, the generation time of the pseudo-random number sequence is truly random. Therefore, the generation delay time of each pseudo-random number sequence is unpredictable, i.e., truly random. In other words, the generation delay time of each pseudo-random number sequence is unpredictable and truly random. The generation delay time can be determined using the CPU timestamp of each round's pseudo-random number sequence.
[0071] In one embodiment, step S102 includes:
[0072] Obtain the CUP timestamp of the first pseudo-random number and the CUP timestamp of the last pseudo-random number;
[0073] The time difference between the CUP timestamp of the first pseudo-random number and the CUP timestamp of the last pseudo-random number is determined as the generation delay time of the pseudo-random number sequence.
[0074] For example, if the pseudo-random number sequence includes N pseudo-random numbers, the CPU timestamp of the first pseudo-random number is T1, and the CPU timestamp of the second pseudo-random number is T... N Then the generation delay time of the pseudo-random number sequence is equal to the CPU timestamp T of the Nth pseudo-random number. N - CPU timestamp T1 for the 11th pseudo-random number. In this way, the CPU timestamp is used to obtain the high-precision generation delay time each time a pseudo-random number is generated.
[0075] Step S103: Determine the offset of each pseudo-random number based on the generation delay time.
[0076] In this embodiment, since the generation delay of the pseudo-random number sequence is unpredictable (i.e., the generation delay is truly random), the offset of each pseudo-random number is determined based on the generation delay to ensure that truly random numbers can be obtained subsequently. Exemplarily, the generation delay of the pseudo-random number sequence can be used as the offset of each pseudo-random number. Alternatively, operations such as addition, subtraction, multiplication, and division can be performed on the generation delay of the pseudo-random number sequence to obtain the offset of each pseudo-random number.
[0077] Step S104: Generate a true random number based on each pseudo-random number and its offset.
[0078] In one embodiment, step S104 includes:
[0079] The sum of each pseudo-random number and its offset is determined as a true random number.
[0080] This speeds up the generation of random numbers, and the generated numbers are truly random.
[0081] The following explains how to calculate the pseudo-random number sequence for each round using the formula aj=Aiai+Bi+TmodMi.
[0082] First, initialize the first initial constant sequence A. i Second initial constant sequence B i The third initial constant sequence M i Set the initial generation delay time to 0 and initialize the initial pseudo-random number sequence a. i If 1 ≤ i ≤ N, determine whether all pseudo-random numbers in each round of the pseudo-random number sequence have been generated. If yes, output the pseudo-random number sequence for each round. If not, record the current CPU timestamp T0. Calculate the i-th pseudo-random number in each round of the pseudo-random number sequence according to the formula aj = Ai + Bi + T mod Mi. The meaning of each letter in the formula is explained in other parts of this embodiment and will not be repeated here. Determine whether i is less than or equal to N. If yes, assign the value of i+1 to i, and calculate the next pseudo-random number according to the aforementioned formula. When i is greater than N, record the current CPU timestamp T1, and output or record the current N pseudo-random numbers a. i Calculate the time difference between CPU timestamp T1 and CPU timestamp T0, and use this time difference as the delay time generated in the previous round when calculating the pseudo-random number sequence in the next round.
[0083] The true random number generation method provided in this embodiment utilizes a pseudo-random number generation algorithm to generate a pseudo-random number sequence, which includes multiple pseudo-random numbers. It determines the generation delay time of the pseudo-random number sequence, wherein the generation delay time is the time required to generate the first pseudo-random number to the last pseudo-random number in the sequence. It then determines the offset of each pseudo-random number based on the generation delay time. Finally, it generates a true random number based on each pseudo-random number and its offset. In this way, by using the generation delay time of the pseudo-random number sequence as the offset of each pseudo-random number, and obtaining multiple true random numbers based on each pseudo-random number and its offset, a large number of true random numbers can be generated in a short time, improving the speed of true random number generation.
[0084] Example 2
[0085] Furthermore, embodiments of this application provide a true random number generation device.
[0086] like Figure 2 As shown, the true random number generation device 200 includes:
[0087] The first generation module 201 is used to generate a pseudo-random number sequence using a pseudo-random number generation algorithm, wherein the pseudo-random number sequence includes multiple pseudo-random numbers;
[0088] The first determining module 202 is used to determine the generation delay time of the pseudo-random number sequence, wherein the generation delay time is the time required to generate the first pseudo-random number to the last pseudo-random number of the pseudo-random number sequence;
[0089] The second determining module 203 is used to determine the offset of each pseudo-random number based on the generation delay time;
[0090] The second generation module 204 is used to generate a true random number based on each pseudo-random number and its offset.
[0091] In one embodiment, the first determining module 202 is further configured to obtain the CUP timestamp of the first pseudo-random number and the CUP timestamp of the last pseudo-random number;
[0092] The time difference between the CUP timestamp of the first pseudo-random number and the CUP timestamp of the last pseudo-random number is determined as the generation delay time of the pseudo-random number sequence.
[0093] In one embodiment, the second generation module 204 is further configured to determine the sum of each of the pseudo-random numbers and their offsets as a true random number.
[0094] In one embodiment, the first generation module 201 is further configured to use the pseudo-random number generation algorithm to generate the current round of pseudo-random number sequence based on the previous round of pseudo-random number sequence, multiple initial constant sequences, and the previous round generation delay time. The previous round of pseudo-random number sequence includes multiple pseudo-random numbers generated by the pseudo-random number generation algorithm in the previous round, and each of the initial constant sequences includes multiple initial constants.
[0095] In one embodiment, the first generation module 201 is further configured to determine the j-th pseudo-random number of the current round pseudo-random number sequence according to the following formula;
[0096] aj = Aiai + Bi + TmodMi;
[0097] Among them, A i B represents the i-th initial constant in the first initial constant sequence. i M represents the i-th initial constant in the second initial constant sequence. i Let represent the i-th initial constant in the third initial constant sequence, T represent the delay time generated in the previous round, and a i Let a represent the i-th pseudo-random number in the previous round of pseudo-random number sequence. j Let represent the j-th pseudo-random number in the current round of pseudo-random number sequence, where mod represents the modulo operation, and j = i.
[0098] In one embodiment, the first generation module 201 is further configured to set an initial generation delay time, an initial random number sequence, and a plurality of the initial constant sequences;
[0099] The pseudo-random number generation algorithm is used to determine the first round of pseudo-random number sequence based on the initial generation delay time, the initial random number sequence, and multiple initial constant sequences.
[0100] In one embodiment, the first generation module 201 is further configured to control the pseudo-random number generation algorithm to generate the pseudo-random number sequence through the AVX instruction set.
[0101] The true random number generation device 200 provided in this embodiment can implement the true random number generation method provided in Embodiment 1. To avoid repetition, it will not be described again here.
[0102] The true random number generation device provided in this embodiment uses a pseudo-random number generation algorithm to generate a pseudo-random number sequence, which includes multiple pseudo-random numbers. It determines the generation delay time of the pseudo-random number sequence, wherein the generation delay time is the time required to generate the first pseudo-random number to the last pseudo-random number in the sequence. It determines the offset of each pseudo-random number based on the generation delay time. Finally, it generates a true random number based on each pseudo-random number and its offset. In this way, by using the generation delay time of the pseudo-random number sequence as the offset of each pseudo-random number, multiple true random numbers are obtained based on each pseudo-random number and its offset, generating a large number of true random numbers in a short time, thus improving the speed of true random number generation.
[0103] Example 3
[0104] Furthermore, this application provides an electronic device, including a memory and a processor. The memory stores a computer program, which executes the true random number generation method provided in Embodiment 1 when the computer program is run on the processor.
[0105] The electronic device provided in this embodiment can implement the true random number generation method provided in Embodiment 1. To avoid repetition, it will not be described again here.
[0106] Example 4
[0107] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the true random number generation method provided in Embodiment 1.
[0108] In this embodiment, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.
[0109] The computer-readable storage medium provided in this embodiment can implement the true random number generation method provided in Embodiment 1. To avoid repetition, it will not be described again here.
[0110] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal that includes that element.
[0111] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0112] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A method for generating truly random numbers, characterized in that, The method, applied in the field of data processing technology, includes: A pseudo-random number sequence is generated using a pseudo-random number generation algorithm, wherein the pseudo-random number sequence includes multiple pseudo-random numbers; Determine the generation delay time of the pseudo-random number sequence, wherein the generation delay time is the time required to generate the first pseudo-random number to the last pseudo-random number in the pseudo-random number sequence; The offset of each pseudo-random number is determined based on the generation delay time; Generate a true random number based on each pseudo-random number and its offset; Determining the generation delay time of the pseudo-random number sequence includes: Obtain the CPU timestamp of the first pseudo-random number and the CPU timestamp of the last pseudo-random number; The time difference between the CPU timestamp of the first pseudo-random number and the CPU timestamp of the last pseudo-random number is determined as the generation delay time of the pseudo-random number sequence. The method of generating a pseudo-random number sequence using a pseudo-random number generation algorithm includes: The pseudo-random number generation algorithm is used to generate the current round of pseudo-random number sequence based on the previous round of pseudo-random number sequence, multiple initial constant sequences, and the previous round generation delay time. The previous round of pseudo-random number sequence includes multiple pseudo-random numbers generated by the pseudo-random number generation algorithm in the previous round, and each of the initial constant sequences includes multiple initial constants. The pseudo-random number generation algorithm generates the current round's pseudo-random number sequence based on the previous round's pseudo-random number sequence, multiple initial constant sequences, and the previous round's generation delay time. The previous round's pseudo-random number sequence includes multiple pseudo-random numbers generated by the algorithm in the previous round. Each initial constant sequence includes multiple initial constants, including: The j-th pseudo-random number in the current round of pseudo-random number sequence is determined according to the following formula; ; in, This represents the i-th initial constant in the first initial constant sequence. This represents the i-th initial constant in the second initial constant sequence. This represents the i-th initial constant in the third initial constant sequence, and T represents the delay time generated in the previous round. This represents the i-th pseudo-random number in the previous round of pseudo-random number sequence. Let represent the j-th pseudo-random number in the current round of pseudo-random number sequence, where mod represents the modulo operation, and j = i; The method of generating a pseudo-random number sequence using a pseudo-random number generation algorithm includes: Set the initial generation delay time, the initial random number sequence, and multiple initial constant sequences; The pseudo-random number generation algorithm is used to determine the first round of pseudo-random number sequence based on the initial generation delay time, the initial random number sequence, and multiple initial constant sequences.
2. The method according to claim 1, characterized in that, The step of generating a true random number based on each pseudo-random number and its offset includes: The sum of each pseudo-random number and its offset is determined as a true random number.
3. The method according to claim 1, characterized in that, The method of generating a pseudo-random number sequence using a pseudo-random number generation algorithm includes: The pseudo-random number sequence is generated by controlling the pseudo-random number generation algorithm through the AVX instruction set.
4. A true random number generation device, characterized in that, The device, applied in the field of data processing technology, includes: The first generation module is used to generate a pseudo-random number sequence using a pseudo-random number generation algorithm, wherein the pseudo-random number sequence includes multiple pseudo-random numbers; The first determining module is used to determine the generation delay time of the pseudo-random number sequence, wherein the generation delay time is the time required to generate the first pseudo-random number to the last pseudo-random number of the pseudo-random number sequence; The second determining module is used to determine the offset of each pseudo-random number based on the generation delay time; The second generation module is used to generate a true random number based on each pseudo-random number and its offset. Determining the generation delay time of the pseudo-random number sequence includes: Obtain the CPU timestamp of the first pseudo-random number and the CPU timestamp of the last pseudo-random number; The time difference between the CPU timestamp of the first pseudo-random number and the CPU timestamp of the last pseudo-random number is determined as the generation delay time of the pseudo-random number sequence. The method of generating a pseudo-random number sequence using a pseudo-random number generation algorithm includes: The pseudo-random number generation algorithm is used to generate the current round of pseudo-random number sequence based on the previous round of pseudo-random number sequence, multiple initial constant sequences, and the previous round generation delay time. The previous round of pseudo-random number sequence includes multiple pseudo-random numbers generated by the pseudo-random number generation algorithm in the previous round, and each of the initial constant sequences includes multiple initial constants. The pseudo-random number generation algorithm generates the current round's pseudo-random number sequence based on the previous round's pseudo-random number sequence, multiple initial constant sequences, and the previous round's generation delay time. The previous round's pseudo-random number sequence includes multiple pseudo-random numbers generated by the algorithm in the previous round. Each initial constant sequence includes multiple initial constants, including: The j-th pseudo-random number in the current round of pseudo-random number sequence is determined according to the following formula; ; in, This represents the i-th initial constant in the first initial constant sequence. This represents the i-th initial constant in the second initial constant sequence. This represents the i-th initial constant in the third initial constant sequence, and T represents the delay time generated in the previous round. This represents the i-th pseudo-random number in the previous round of pseudo-random number sequence. Let represent the j-th pseudo-random number in the current round of pseudo-random number sequence, where mod represents the modulo operation, and j = i; The method of generating a pseudo-random number sequence using a pseudo-random number generation algorithm includes: Set the initial generation delay time, the initial random number sequence, and multiple initial constant sequences; The pseudo-random number generation algorithm is used to determine the first round of pseudo-random number sequence based on the initial generation delay time, the initial random number sequence, and multiple initial constant sequences.
5. An electronic device, characterized in that, The device includes a memory and a processor, wherein the memory stores a computer program that executes the true random number generation method according to any one of claims 1 to 3 when the processor is running.
6. A computer-readable storage medium, characterized in that, It stores a computer program that, when run on a processor, executes the true random number generation method according to any one of claims 1 to 3.
Citation Information
Patent Citations
True random number generation method
CN107368283A
True random number generation method, device and equipment and computer medium
CN110221811A