+

CN112306457A - Random number generation method and device - Google Patents

Random number generation method and device Download PDF

Info

Publication number
CN112306457A
CN112306457A CN202010789732.9A CN202010789732A CN112306457A CN 112306457 A CN112306457 A CN 112306457A CN 202010789732 A CN202010789732 A CN 202010789732A CN 112306457 A CN112306457 A CN 112306457A
Authority
CN
China
Prior art keywords
random number
internal state
splicing
random
hash operation
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010789732.9A
Other languages
Chinese (zh)
Other versions
CN112306457B (en
Inventor
李登峰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhou Rongan Digital Technology Beijing Co ltd
Original Assignee
Shenzhou Rongan Technology Beijing Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhou Rongan Technology Beijing Co ltd filed Critical Shenzhou Rongan Technology Beijing Co ltd
Priority to CN202010789732.9A priority Critical patent/CN112306457B/en
Publication of CN112306457A publication Critical patent/CN112306457A/en
Application granted granted Critical
Publication of CN112306457B publication Critical patent/CN112306457B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/58Random or pseudo-random number generators
    • G06F7/588Random number generators, i.e. based on natural stochastic processes

Landscapes

  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computational Mathematics (AREA)
  • Mathematical Analysis (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention discloses a random number generation method and a device, relates to the technical field of computers, and mainly aims to perform different levels of customized optimization on the randomness of random numbers output by an original random number generator; the main technical scheme comprises: acquiring N first random numbers output by a random number generator, wherein N is greater than or equal to 1, and determining the optimization level of randomness of outputting a second random number by adjusting the size of N; calculating a first internal state of the first random number every time one first random number is obtained, and carrying out hash operation based on the first internal state to obtain a random number segment corresponding to the first random number; and splicing the random number segments of the first random numbers to form second random numbers.

Description

Random number generation method and device
Technical Field
The invention relates to the technical field of computers, in particular to a random number generation method and device.
Background
The random number generator is an indispensable part of a security device such as a security chip, and is capable of providing a security system with a random number having sufficient randomness so that an application related to information encryption and decryption uses the random number output by the random number generator to form data such as a key, authorization authentication information, integrity authentication information, and the like in an encryption system.
At present, after the chip random number generator is subjected to sizing, the randomness of the generated hardware random number is fixed and invariable, and with the continuous improvement of the safety standard, the randomness of the random number output by the chip random number generator in the application of a safety system can not meet the safety requirement of the safety system, so that certain potential safety hazards can be brought to the safety system. If the random number generator in the safety system can output the random number with the randomness meeting the safety requirement of the safety system, the hardware where the random number generator is located is usually directly replaced, and a new random number generator capable of outputting the random number with the randomness meeting the safety requirement of the safety system is arranged on the replaced hardware. Therefore, how to perform different levels of customization and optimization aiming at the randomness of the random numbers output by the random number generator under the conditions of being compatible with the original hardware environment and balancing the hardware resource occupation and the modification cost is a problem which needs to be solved at present.
Disclosure of Invention
In view of this, the present invention provides a method and an apparatus for generating random numbers, and mainly aims to perform different levels of customized optimization on the randomness of the random numbers output by an original random number generator.
In a first aspect, the present invention provides a random number generation method, including:
acquiring N first random numbers output by a random number generator, wherein N is greater than or equal to 1, and determining the optimization level of randomness of outputting a second random number by adjusting the size of N;
calculating a first internal state of the first random number every time one first random number is obtained, and carrying out hash operation based on the first internal state to obtain a random number segment corresponding to the first random number;
and splicing the random number segments of the first random numbers to form second random numbers.
In a second aspect, the present invention provides a random number generation apparatus, comprising:
the acquisition unit is used for acquiring N first random numbers output by the random number generator, wherein N is greater than or equal to 1, and the randomness optimization level of the second random number is determined by adjusting the size of N;
the operation unit is used for calculating a first internal state of the first random number every time one first random number is acquired, and carrying out hash operation based on the first internal state to obtain a random number segment corresponding to the first random number;
and the splicing unit is used for splicing the random number segments of the first random numbers to form second random numbers.
In a third aspect, the present invention provides a computer-readable storage medium, where the storage medium includes a stored program, and when the program runs, the apparatus on which the storage medium is located is controlled to execute the method for generating random numbers according to the first aspect.
In a fourth aspect, the present invention provides a storage management apparatus, including:
a memory for storing a program;
a processor, coupled to the memory, for executing the program to perform the random number generation method of the first aspect.
By means of the technical scheme, the random number generation method and the random number generation device determine the optimization level of the randomness of the output second random number by adjusting the number of the first random numbers output by the random number generator. And when a first random number output by one random number generator is obtained, calculating a first internal state of the first random number, and carrying out hash operation based on the first internal state to obtain a random number segment corresponding to the first random number. And after the random number segments corresponding to the preset number of first random numbers are calculated, splicing the random number segments of the first random numbers to form a second random number. Therefore, the scheme provided by the invention can directly utilize the random number output by the random number generator as input without changing hardware with the random number generator, and the randomness of the random number output by the random number generator is enhanced by using the operation of the hash algorithm, thereby completing the customization and optimization of the randomness of the random number output by the random number generator at different levels.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
FIG. 1 is a flow chart illustrating a method for random number generation according to an embodiment of the present invention;
FIG. 2 is a flow chart illustrating a method for random number generation according to another embodiment of the present invention;
FIG. 3 is a flow chart illustrating a method for random number generation according to yet another embodiment of the present invention;
fig. 4 is a schematic structural diagram illustrating a random number generation apparatus according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram illustrating a random number generation apparatus according to another embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
As shown in fig. 1, an embodiment of the present invention provides a random number generation method, which mainly includes:
101. acquiring N first random numbers output by the random number generator, wherein N is greater than or equal to
And 1, determining an optimization level for outputting the randomness of the second random number by adjusting the size of N.
In practical application, in order to improve some random number generators which generate random numbers with low randomness, the random number generators which need to be subjected to random number randomness optimization are selected as random number generators which output first random numbers. The random number generator can be a random number generator deployed on hardware such as a USBKey, an intelligent password device, an intelligent authentication device or a security chip. The specific type of the random number generator is not particularly limited in this embodiment, and optionally, the random number generator may be a true random number generator or a pseudo random number generator. In addition, it should be noted that, in the present embodiment, when the randomness of the random number output by the random number generator is optimized, the optimization can be completed based on the random number output by the random number generator directly without performing hardware modification on a device or a chip on which the random number generator is deployed. By optimizing the randomness of the random numbers output by the random number generator, the old hardware or the chip can output the random numbers with the randomness meeting the safety requirement of the safety system, thereby prolonging the product life cycle of the old hardware or the chip.
In practical application, when the random number output by the random number generator is optimized, N first random numbers output by the random number generator need to be acquired, and the optimization level of randomness of outputting a second random number is determined by adjusting the size of N. Wherein the larger N is, the higher the optimization level of outputting the randomness of the second random number is, and the smaller N is, the lower the optimization level of outputting the randomness of the second random number is. The character length and the number of the first random number output by the random number generator can be customized according to the random strength of the random number output by the random number generator, so that the optimization process of controlling the randomness of the random number is flexible. The character length and number of the first random number output by the random number generator will be described as follows:
the character size of the first random number output by the random number generator can be determined by the following method: firstly, in order to obtain a random number meeting the service requirement, the character length of a first random number output by the random number generator is set by a user; secondly, in order to ensure the better randomness of the random number, the character length of the first random number output by the random number generator is the character length with the optimal randomness output by the random number generator, and the optimal length needs to balance factors such as the occupation of subsequent operation hardware resources, the generation efficiency of the random number and the like.
The number of first random numbers output by the random number generator may be determined by: a random number is used to determine a random number segment, each random number segment having a particular character length, so that the number of first random numbers obtained is determined based on the expected character length of the second random number and the character length of each random number segment. Illustratively, each random number segment has a length of 10 characters, and the expected length of the second random number is 40 characters, it is necessary to obtain 4 first random numbers output by the random number generator.
It should be noted that the N first random numbers may be random numbers that are continuously output by the random number generator. In addition, in order to improve the randomness of the second random numbers, the acquired N first random numbers output by the random number generator may have different character lengths.
102. And calculating a first internal state of the first random number every time one first random number is obtained, and carrying out hash operation based on the first internal state to obtain a random number segment corresponding to the first random number.
The first internal state may be considered as a seed for generating the second random number, which is the basis for generating the second random number, and which directly determines the randomness of the second random number. In this embodiment, since the first internal state used for generating each random number segment is obtained according to the corresponding first random number, the randomness of each random number segment is higher, so that the randomness of the second random number obtained according to each random number segment is better.
A method of calculating a first internal state of a first random number is described below, the method including the following steps one to two:
step one, determining the internal state of a sample corresponding to the first random number.
Specifically, the determination of the internal state of the sample is related to the calculation of the internal state of the sample when the first random number is the several bits, so the method for determining the internal state of the sample corresponding to the first random number at least includes the following steps:
first, when the first random number is the first one to perform the first internal state calculation, the last first random number adjacent to the first random number is determined as the sample internal state corresponding to the first random number.
Specifically, in order to determine the internal state of the first sample of the first random number subjected to the first internal state calculation, a previous first random number output by the random number generator and adjacent to the first random number needs to be obtained, the random number of the previous first random number does not need to be calculated, and only the previous first random number is used as the internal state of the first sample of the first random number subjected to the first internal state calculation. For example, the first random number to perform the first internal state calculation is a first random number 1, the random number generator outputs a first random number 0 before the first random number 1, and the first random number 0 is adjacent to the first random number 1, and then the first random number 0 is determined as the sample internal state of the first random number 1.
And secondly, when the first random number is the non-first random number for carrying out the first internal state calculation, determining the first internal state of the last first random number adjacent to the first random number as the internal state of the sample corresponding to the first random number.
Specifically, when the first random number is a first random number that is not the first to perform the first internal state calculation, in order to ensure the randomness of the generated second random number, the first internal state of the previous first random number needs to be used as the sample internal state of the first random number that is not the first to perform the first internal state calculation. This operation not only associates the random number segment generated each time with the previous time, but also ensures that the internal state of the sample used each time is different, thereby ensuring the randomness of the random number segment obtained by each first random number.
Illustratively, the first random number 2 is a non-first random number for which the first internal state calculation is performed, before which the first random number 1 has already performed the first internal state calculation, and the random number segment corresponding to the first random number 1 is determined, so the first internal state of the first random number 1 is determined as the sample internal state of the first random number 2.
Performing hash operation on at least one of the internal state of the sample of the previous first random number adjacent to the first random number and a second preset value to obtain a second internal state of the previous first random number; and determining the internal state of the sample corresponding to the first random number based on the first internal state and the second internal state of the last first random number.
The second method is a parallel technical scheme, and can be flexibly selected according to specific service requirements in practical application.
Specifically, when the first random number is a first random number that is not the first to perform the first internal state calculation, in order to ensure the randomness of the generated second random number, the first internal state and the second internal state of the previous first random number need to be used, and the sample internal state is determined for the first random number that is not the first to perform the first internal state calculation. This operation not only associates the random number segment generated each time with the previous time, but also ensures that the internal state of the sample used each time is different, thereby ensuring the randomness of the random number segment obtained by each first random number.
A method of determining the second internal state of the last first random number is described below, which includes the following two types:
when the hash operation is performed only according to the internal state or the second preset value of the sample of the previous first random number adjacent to the first random number to obtain the second internal state of the previous first random number, the hash operation is performed according to the following formula (1), where the formula (1) is: v2 ═ H (a | V01), where V2 characterizes the second internal state of the last first random number, V01 characterizes the sample internal state of the last first random number, a characterizes the second preset value, H characterizes the hash operation, | characterizes the logical or. It should be noted that the second preset value may be set based on the service requirement, and optionally, may be a constant value or a variable sequence.
When hash operation is required to be carried out according to the internal state of the sample of the previous first random number adjacent to the first random number and a second preset value to obtain the second internal state of the previous first random number, splicing the internal state of the sample of the previous first random number adjacent to the first random number and the second preset value; and carrying out Hash operation on the splicing result to obtain a second internal state of the last first random number. When splicing, the internal state of the previous sample of the first random number adjacent to the first random number may be located before the second preset value or after the second preset value. Alternatively, the process may be implemented by the following formula (2), where the formula (2) is: v2 ═ H (a + V01), where V2 characterizes the second internal state of the last first random number, V01 characterizes the sample internal state of the last first random number, a characterizes the second preset value, H characterizes the hash operation, and + characterizes the concatenation. It should be noted that the second preset value may be set based on the service requirement, and optionally, may be a constant value or a variable sequence.
A method for determining a sample internal state corresponding to a previous first random number based on a first internal state and a second internal state of the first random number is described below, where the method specifically includes the following steps: performing hash operation on at least one of the first internal state and the third preset value of the previous first random number to obtain a hash operation result; splicing the hash operation result, the first internal state of the last first random number, the second internal state of the last first random number and a fourth preset value; and determining the remainder result of the splicing result on the fifth preset numerical value as the internal state of the sample corresponding to the first random number.
When only the hash operation is performed on the first internal state or the third preset value of the last first random number, the hash operation is directly performed. When the hash operation needs to be performed on the first internal state and the third preset value of the previous first random number, the first internal state and the third preset value of the previous first random number need to be spliced first, and then the hash operation is performed on the splicing result.
When the hash operation result, the first internal state of the previous first random number, the second internal state of the previous first random number, and the fourth preset value are spliced, the splicing sequence may be determined according to the service requirement without specific limitation.
The fifth preset value may be determined based on service requirements or may be determined according to the character length of the random number segment. Optionally, the fifth preset numerical value may be len power of 2, where len represents the character length of the random number segment.
For example, the process of determining the internal state of the sample corresponding to the first random number based on the first internal state and the second internal state of the last first random number may be implemented by the following formula (3), where the formula (3) is: v02 ═ V1+ H (d | V1) + V2+ e) mod2len, wherein V02 represents the internal state of the sample corresponding to the first random number, V1 represents the first internal state of the last first random number, H represents the hash operation, d represents the third preset value, V2 represents the second internal state of the last first random number, e represents the fourth preset value, mod represents the remainder function,the power of the symbol is characterized and len the character length of the random number segment.
And step two, performing Hash operation on at least one of the first random number, the first preset numerical value and the internal state of the sample to obtain a first internal state of the first random number.
Specifically, the method for obtaining the first internal state of the first random number by performing hash operation on at least one of the first random number, the first preset value, and the internal state of the sample includes the following two steps:
when the hash operation is performed only according to the first random number or the first preset value or the internal state of the sample to obtain the first internal state of the first random number, the hash operation is performed according to the following formula (4), where the formula (4) is: v3 ═ H (b | a | V02), where V3 characterizes the first internal state of the first random number, V02 characterizes the sample internal state of the first random number, b characterizes the first preset value, H characterizes the hash operation, | characterizes the logical or. It should be noted that the first preset value may be set based on the service requirement, and optionally, may be a constant value or a variable sequence.
When at least two of the first random number, the first preset numerical value and the internal state of the sample need to be subjected to Hash operation to obtain the first internal state of the first random number, splicing the at least two of the first random number, the first preset numerical value and the internal state of the sample, and performing Hash operation on the splicing result to obtain the first internal state of the first random number. It should be noted that the splicing order of at least two of the first random number, the first preset value, and the internal state of the sample may be determined based on the service requirement, and is not limited herein. Illustratively, the hash operation is performed according to the following equation (5), where the second equation is: v3 ═ H (b + a + V02), where V3 characterizes the first internal state of the first random number, V02 characterizes the sample internal state of the first random number, b characterizes the first preset value, H characterizes the hash operation, + characterizes the concatenation. It should be noted that the first preset value may be set based on the service requirement, and optionally, b is 1.
A method for performing a hash operation based on the first internal state to obtain a random number segment corresponding to the first random number is described below, where the method specifically includes: performing hash operation on at least one of the first internal state and the sixth preset value to obtain a hash operation result; splicing the first internal state and the Hash operation result, and taking the residue of the splicing result on a seventh preset numerical value; and carrying out Hash operation on the remainder result to obtain a random number segment corresponding to the first random number.
When only the first internal state or the sixth preset value is subjected to hash operation, the hash operation is directly performed. When the hash operation needs to be performed on the first internal state and the sixth preset value, the first internal state and the sixth preset value need to be spliced first, and then the hash operation is performed on a splicing result.
When the hash operation result and the first internal state are spliced, the splicing sequence may be determined according to the service requirement without specific limitation.
The seventh preset value may be determined based on the service requirement, or may be determined according to the character length of the random number segment. Optionally, the seventh preset numerical value may be len power of 2, where len represents the character length of the random number segment.
For example, the process of performing the hash operation based on the first internal state to obtain the random number segment corresponding to the first random number may be implemented by the following formula (6), where the formula (6) is: t ═ H (V3+ H (f | V3) mod2len, where T represents a random number segment corresponding to the first random number, V3 represents a first internal state of the first random number, H represents a hash operation, f represents a sixth preset value, mod represents a remainder function,the power of the symbol is characterized and len the character length of the random number segment.
103. And splicing the random number segments of the first random numbers to form second random numbers.
In practical application, when the number of the first random number is only one, the random number segment of the first random number is directly used as the second random number without performing splicing processing on the random number segment of the first random number. When the number of the first random numbers is two or more, each first random number has its own random number segment, and in order to obtain a second random number with better randomness, the second random number needs to be obtained by splicing the random number segments of the first random numbers.
The following describes a method for performing a splicing process on random number segments of each first random number, where the splicing process method includes at least the following two methods:
the method I comprises the steps of distributing splicing sequences to random numbers of first random numbers in a segmented mode; and splicing the random number segments of the first random numbers according to the splicing sequence of the random number segments to form second random numbers.
The allocation of the splicing sequence described herein includes at least the following:
first, according to the output order of the first random numbers output by the random number generator, the random number of each first random number is distributed with a splicing order in segments.
Illustratively, the first random number 1 corresponds to random number segment 1, the second random number corresponds to random number segment 2, and the third random number corresponds to random number segment 3. The random number generator sequentially outputs a first random number 1, a first random number 2 and a third random number 3, so that the splicing sequence of the random number segment 1 is located at a first position, the splicing sequence of the random number segment 2 is located at a second position, and the splicing sequence of the random number segment 3 is located at a third position.
And secondly, reading a preset splicing sequence of the random number segments of each first random number through a preset interface, and distributing the splicing sequence for the random number segments of each first random number based on the preset splicing sequence.
Specifically, the preset splicing sequence is preset by a user based on the splicing requirement and is stored in a specific storage position, and when splicing processing needs to be performed on the random number segments, the preset splicing sequence is read from the specific storage position through a preset interface. Optionally, the preset interface may be an API interface. The preset splicing sequence is used for being preset to a storage position in advance, so that the splicing sequence of the random number segments can meet the splicing requirement of a user to the maximum extent.
Illustratively, the preset splicing sequence is as follows: the splicing sequence of the random number segment 3 is located at the first position, the splicing sequence of the random number segment 1 is located at the second position, and the splicing sequence of the random number segment 2 is located at the third position. After the preset splicing sequence is read through the preset interface, the splicing sequence which is sectionally distributed to each random number is as follows: the splicing sequence of the random number segment 3 is located at the first position, the splicing sequence of the random number segment 1 is located at the second position, and the splicing sequence of the random number segment 2 is located at the third position.
Thirdly, randomly distributing a splicing sequence to the random number segments of each first random number.
Specifically, since the order of combining the random number segments is randomly allocated and is not random, the second random number obtained by combining the random number segments according to the order of combining has the optimal randomness.
Extracting character strings with set length from the random number segments of the first random numbers respectively; and splicing the extracted character strings to form a second random number.
Specifically, the method for extracting the character string from the random number segment of each first random number comprises the following steps: and determining an extraction position and an extraction character length of the random number segment of each first random number, and extracting the character string based on the extraction position and the extraction character length.
It should be noted that the extraction positions of the random number segments of the first random numbers may be the same or different, and the extraction character lengths of the random number segments of the first random numbers may be the same or different.
Illustratively, the random number segment of the first random number 1 and the random number segment of the second random number are each a character string composed of 10 characters, the characters located at the first 5 bits are extracted from the random number segment of the first random number 1, and the characters located at the first 5 bits are extracted from the random number segment of the first random number 2.
Illustratively, the random number segment of the first random number 1 and the random number segment of the second random number are each a character string composed of 10 characters, the characters located at the first 5 bits are extracted from the random number segment of the first random number 1, and 5 characters are successively extracted from the beginning located at the 2 nd bit from the random number segment of the first random number 2.
Specifically, after extracting the character strings with the set length from the random number segments of the first random numbers, the extracted character strings need to be pieced together, and in order to improve the randomness of the second random numbers obtained by piecing together, the method for piecing together the character strings at least includes the following steps: first, according to the output order of the first random numbers output by the random number generator, the character strings extracted from the random number segments of the first random numbers are allocated with a splicing order, and the extracted character strings are spliced according to the allocated splicing order. Secondly, reading a preset splicing sequence of the random number segments of the first random numbers through a preset interface, distributing a splicing sequence for the random number segments extracted from the random number segments of the first random numbers based on the preset splicing sequence, and splicing the extracted character strings according to the distributed splicing sequence. Thirdly, randomly splicing each extracted character string.
According to the random number generation method provided by the embodiment of the invention, the optimization level of the randomness of the output second random number is determined by adjusting the number of the first random numbers output by the random number generator. And when a first random number output by one random number generator is obtained, calculating a first internal state of the first random number, and carrying out hash operation based on the first internal state to obtain a random number segment corresponding to the first random number. And after the random number segments corresponding to the preset number of first random numbers are calculated, splicing the random number segments of the first random numbers to form a second random number. Therefore, the scheme provided by the embodiment of the invention can directly utilize the random number output by the random number generator as input without changing hardware with the random number generator, and the randomness of the random number output by the random number generator is enhanced by using the operation of the hash algorithm, so that the random number output by the random number generator is customized and optimized at different levels.
Further, according to the method shown in fig. 1, another embodiment of the present invention further provides a random number generation method, as shown in fig. 2, the method mainly includes:
201. determining randomness of the random number generator.
When the randomness of the random numbers generated by the random number generator is insufficient, then the random numbers output by the random number generator will provide low security because the randomness of the random number generator needs to be determined. The method of determining randomness of the random number generator comprises: firstly, whether obvious relation exists between random numbers output by a random number generator is determined; secondly, determining whether the random numbers output by the random number generator are averaged in the distribution area; thirdly, whether the random number output by the random number generator appears to be circulated in a short time is determined.
202. A first random number length is determined based on the randomness.
After determining the randomness of the random number generator, the length of the first random number is determined. The random number generator outputs first random numbers with the length, the randomness of the first random numbers is better, obvious relation does not exist among the output first random numbers, the first random numbers are distributed in a distribution area in a tie way, and the first random numbers output in the preset time length do not have circulation.
203. Controlling the random number generator to output a first random number having the first random number length.
204. N first random numbers output by the random number generator are obtained.
Specifically, the optimization level of outputting the randomness of the second random number can be determined by adjusting the size of N.
205. Determining whether the first random number is the first random number for performing the first internal state calculation every time one first random number is obtained; if yes, go to 206; otherwise, 207 is performed.
206. When the first random number is the first one to perform the first internal state calculation, the last first random number adjacent to the first random number is determined as the sample internal state corresponding to the first random number, and 208 is performed.
207. And when the first random number is a non-first random number for carrying out first internal state calculation, determining a first internal state of a last first random number adjacent to the first random number as a sample internal state corresponding to the first random number.
208. And performing hash operation on at least one of the first random number, a first preset numerical value and the internal state of the sample to obtain a first internal state of the first random number.
209. And performing hash operation on at least one of the first internal state and a sixth preset value to obtain a hash operation result.
210. And splicing the first internal state and the Hash operation result, and taking the residue of the splicing result on a seventh preset numerical value.
211. And carrying out Hash operation on the remainder result to obtain a random number segment corresponding to the first random number.
212. And according to the output sequence of the first random numbers output by the random number generator, distributing a splicing sequence to the random number segments of the first random numbers.
213. And splicing the random number segments of the first random numbers according to the splicing sequence of the random number segments to form the second random numbers.
Further, according to the method shown in fig. 1, another embodiment of the present invention further provides a random number generation method, as shown in fig. 3, the method mainly includes:
301. determining randomness of the random number generator.
302. A first random number length is determined based on the randomness.
303. Controlling the random number generator to output a first random number having the first random number length.
304. N first random numbers output by the random number generator are obtained.
305. Determining whether the first random number is the first random number for performing the first internal state calculation every time one first random number is obtained; if yes, go to 306; otherwise, 307 is performed.
306. When the first random number is the first one to perform the first internal state calculation, the last first random number adjacent to the first random number is determined as the sample internal state corresponding to the first random number, and 311 is performed.
307. And carrying out Hash operation on at least one of the internal state of the sample of the previous first random number adjacent to the first random number and a second preset value to obtain a second internal state of the previous first random number.
308. And performing hash operation on at least one of the first internal state and the third preset value of the last first random number to obtain a hash operation result.
309. And splicing the hash operation result, the first internal state of the last first random number, the second internal state of the last first random number and a fourth preset value.
310. And determining a remainder result of the splicing result on a fifth preset numerical value as a sample internal state corresponding to the first random number.
311. And performing hash operation on at least one of the first random number, a first preset numerical value and the internal state of the sample to obtain a first internal state of the first random number.
312. And performing hash operation on at least one of the first internal state and a sixth preset value to obtain a hash operation result.
313. And splicing the first internal state and the Hash operation result, and taking the residue of the splicing result on a seventh preset numerical value.
314. And carrying out Hash operation on the remainder result to obtain a random number segment corresponding to the first random number.
315. Character strings with set lengths are respectively extracted from the random number segments of the first random numbers.
316. And splicing the extracted character strings to form the second random number.
Further, according to the above method embodiment, another embodiment of the present invention further provides a random number generating apparatus, as shown in fig. 4, the apparatus includes:
an obtaining unit 41, configured to obtain N first random numbers output by the random number generator, where N is greater than or equal to 1, and determine an optimization level for outputting randomness of a second random number by adjusting the size of N;
an operation unit 42, configured to calculate a first internal state of the first random number each time one first random number is obtained, and perform a hash operation based on the first internal state to obtain a random number segment corresponding to the first random number;
and a splicing unit 43, configured to splice the random number segments of each first random number to form a second random number.
The random number generation device provided by the embodiment of the invention determines the optimization level of the randomness of the output second random number by adjusting the number of the first random numbers output by the random number generator. And when a first random number output by one random number generator is obtained, calculating a first internal state of the first random number, and carrying out hash operation based on the first internal state to obtain a random number segment corresponding to the first random number. And after the random number segments corresponding to the preset number of first random numbers are calculated, splicing the random number segments of the first random numbers to form a second random number. Therefore, the scheme provided by the embodiment of the invention can directly utilize the random number output by the random number generator as input without changing hardware with the random number generator, and the randomness of the random number output by the random number generator is enhanced by using the operation of the hash algorithm, so that the random number output by the random number generator is customized and optimized at different levels.
Alternatively, as shown in fig. 5, the splicing unit 43 includes:
an assigning module 431, configured to assign a splicing order to the random number segments of each of the first random numbers;
the first splicing module 432 is configured to splice the random number segments of the first random numbers according to the splicing sequence of the random number segments to form the second random number.
Optionally, as shown in fig. 5, the allocating module 431 is configured to allocate a splicing order to the random number segments of each first random number according to the output order of each first random number output by the random number generator; or reading a preset splicing sequence of the random number segments of each first random number through a preset interface, and distributing a splicing sequence to the random number segments of each first random number based on the preset splicing sequence.
Optionally, as shown in fig. 5, the splicing unit 43 includes:
an extracting module 433, configured to extract a character string with a set length from each random number segment of the first random number;
and a second splicing module 434, configured to splice the extracted character strings to form the second random number.
Optionally, as shown in fig. 5, the apparatus further includes:
a determining unit 44 for determining randomness of the random number generator; determining a first random number length based on the randomness;
a control unit 45, configured to control the random number generator to output a first random number having the first random number length.
Optionally, as shown in fig. 5, the operation unit 42 includes:
a determining module 421, configured to determine an internal state of the sample corresponding to the first random number
The first operation module 422 is configured to perform a hash operation on at least one of the first random number, the first preset value, and the internal state of the sample to obtain a first internal state of the first random number.
Optionally, as shown in fig. 5, the first determining module 421 is configured to, when the first random number is a first random number for performing first internal state calculation, determine a last first random number adjacent to the first random number as a sample internal state corresponding to the first random number.
Optionally, as shown in fig. 5, the first determining module 421 is configured to determine, when the first random number is a first random number that is not the first random number and is subjected to first internal state calculation, a first internal state of a last first random number adjacent to the first random number as a sample internal state corresponding to the first random number.
Optionally, as shown in fig. 5, the first determining module 421 is configured to perform a hash operation on at least one of an internal state of a sample of a previous first random number adjacent to the first random number and a second preset value to obtain a second internal state of the previous first random number; and determining the internal state of the sample corresponding to the first random number based on the first internal state and the second internal state of the last first random number.
Optionally, as shown in fig. 5, the first determining module 421 is specifically configured to perform a hash operation on at least one of the first internal state of the last first random number and a third preset value to obtain a hash operation result; splicing a hash operation result, a first internal state of the last first random number, a second internal state of the last first random number and a fourth preset numerical value; and determining a remainder result of the splicing result on a fifth preset numerical value as a sample internal state corresponding to the first random number.
Optionally, as shown in fig. 5, the first determining module 421 is specifically configured to splice an internal state of a sample of a previous first random number adjacent to the first random number with a second preset value; and carrying out Hash operation on the splicing result to obtain a second internal state of the last first random number.
Optionally, as shown in fig. 5, the first operation module 422 is configured to splice at least two of the first random number, the first preset value, and the internal state of the sample; and carrying out Hash operation on the splicing result to obtain a first internal state of the first random number.
Optionally, as shown in fig. 5, the operation unit 42 includes:
a second operation module 423, configured to perform a hash operation on at least one of the first internal state and a sixth preset value to obtain a hash operation result; splicing the first internal state and the Hash operation result, and taking the residue of the splicing result to a seventh preset numerical value; and carrying out Hash operation on the remainder result to obtain a random number segment corresponding to the first random number.
In the random number generation apparatus provided in the embodiment of the present invention, for details of methods used in the operation process of each functional module, reference may be made to the corresponding methods in the method embodiments in fig. 1 to fig. 3 for details, which are not described herein again.
Further, according to the foregoing embodiment, another embodiment of the present invention further provides a computer-readable storage medium, where the storage medium includes a stored program, and when the program runs, the apparatus on which the storage medium is located is controlled to execute any one of the foregoing random number generation methods.
Further, according to the above embodiment, another embodiment of the present invention provides a storage management apparatus, including:
a memory for storing a program;
a processor, coupled to the memory, for executing the program to perform any of the above-described random number generation methods.
In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
It will be appreciated that the relevant features of the method and apparatus described above are referred to one another. In addition, "first", "second", and the like in the above embodiments are for distinguishing the embodiments, and do not represent merits of the embodiments.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The algorithms and displays presented herein are not inherently related to any particular computer, virtual machine, or other apparatus. Various general purpose systems may also be used with the teachings herein. The required structure for constructing such a system will be apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement some or all of the functions of some or all of the components of the method, apparatus and framework for operation of a deep neural network model in accordance with embodiments of the present invention. The present invention may also be embodied as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing the present invention may be stored on computer-readable media or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.

Claims (10)

1. A random number generation method, comprising:
acquiring N first random numbers output by a random number generator, wherein N is greater than or equal to 1, and determining the optimization level of randomness of outputting a second random number by adjusting the size of N;
calculating a first internal state of the first random number every time one first random number is obtained, and carrying out hash operation based on the first internal state to obtain a random number segment corresponding to the first random number;
and splicing the random number segments of the first random numbers to form second random numbers.
2. The method of claim 1, wherein the step of stitching the random number segments of each of the first random numbers to form a second random number comprises:
distributing a splicing sequence to the random number segments of each first random number;
splicing the random number segments of the first random numbers according to the splicing sequence of the random number segments to form second random numbers;
or the like, or, alternatively,
splicing the random number segments of the first random numbers to form second random numbers, wherein the splicing process comprises the following steps:
respectively extracting character strings with set length from the random number segments of the first random numbers;
and splicing the extracted character strings to form the second random number.
3. The method of claim 2, wherein assigning a split order to the random number segments of each of the first random numbers comprises:
according to the output sequence of the first random numbers output by the random number generator, distributing a splicing sequence to the random numbers of the first random numbers in a segmented manner;
or reading a preset splicing sequence of the random number segments of each first random number through a preset interface, and distributing a splicing sequence to the random number segments of each first random number based on the preset splicing sequence.
4. The method of claim 1, wherein performing a hash operation based on the first internal state to obtain a random number segment corresponding to the first random number comprises:
performing hash operation on at least one of the first internal state and a sixth preset value to obtain a hash operation result;
splicing the first internal state and the Hash operation result, and taking the residue of the splicing result to a seventh preset numerical value;
carrying out Hash operation on the remainder result to obtain a random number segment corresponding to the first random number;
and/or the presence of a gas in the gas,
the method further comprises the following steps:
determining randomness of the random number generator;
determining a first random number length based on the randomness;
controlling the random number generator to output a first random number having the first random number length.
5. The method of claim 1, wherein computing the first internal state of the first random number comprises:
determining the internal state of the sample corresponding to the first random number;
and performing hash operation on at least one of the first random number, a first preset numerical value and the internal state of the sample to obtain a first internal state of the first random number.
6. The method of claim 5, wherein determining the internal state of the sample corresponding to the first random number comprises:
when the first random number is the first one for carrying out first internal state calculation, determining the last first random number adjacent to the first random number as a sample internal state corresponding to the first random number;
or the like, or, alternatively,
determining the internal state of the sample corresponding to the first random number, including:
when the first random number is a non-first random number for performing first internal state calculation, determining a first internal state of a last first random number adjacent to the first random number as a sample internal state corresponding to the first random number;
or the like, or, alternatively,
determining the internal state of the sample corresponding to the first random number, including:
performing hash operation on at least one of the internal state of the sample of the previous first random number adjacent to the first random number and a second preset value to obtain a second internal state of the previous first random number;
and determining the internal state of the sample corresponding to the first random number based on the first internal state and the second internal state of the last first random number.
7. The method of claim 6, wherein determining the sample internal state corresponding to the first random number based on the first internal state and the second internal state of the last first random number comprises:
performing hash operation on at least one of the first internal state and the third preset value of the previous first random number to obtain a hash operation result;
splicing a hash operation result, a first internal state of the last first random number, a second internal state of the last first random number and a fourth preset numerical value;
determining a remainder result of the splicing result on a fifth preset numerical value as a sample internal state corresponding to the first random number;
and/or the presence of a gas in the gas,
performing hash operation on the internal state of the sample of the previous first random number adjacent to the first random number and a second preset value to obtain a second internal state of the previous first random number, including:
splicing the internal state of the sample of the last first random number adjacent to the first random number with a second preset value;
and carrying out Hash operation on the splicing result to obtain a second internal state of the last first random number.
8. A random number generation apparatus, comprising:
the acquisition unit is used for acquiring N first random numbers output by the random number generator, wherein N is greater than or equal to 1, and the randomness optimization level of the second random number is determined by adjusting the size of N;
the operation unit is used for calculating a first internal state of the first random number every time one first random number is acquired, and carrying out hash operation based on the first internal state to obtain a random number segment corresponding to the first random number;
and the splicing unit is used for splicing the random number segments of the first random numbers to form second random numbers.
9. A computer-readable storage medium, characterized in that the storage medium includes a stored program, wherein when the program runs, the apparatus on which the storage medium is located is controlled to execute the random number generation method of any one of claims 1 to 7.
10. A storage management apparatus, characterized in that the storage management apparatus comprises:
a memory for storing a program;
a processor, coupled to the memory, for executing the program to perform the random number generation method of any one of claims 1 to 7.
CN202010789732.9A 2020-08-07 2020-08-07 Random number generation method and device Active CN112306457B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010789732.9A CN112306457B (en) 2020-08-07 2020-08-07 Random number generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010789732.9A CN112306457B (en) 2020-08-07 2020-08-07 Random number generation method and device

Publications (2)

Publication Number Publication Date
CN112306457A true CN112306457A (en) 2021-02-02
CN112306457B CN112306457B (en) 2023-07-14

Family

ID=74483626

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010789732.9A Active CN112306457B (en) 2020-08-07 2020-08-07 Random number generation method and device

Country Status (1)

Country Link
CN (1) CN112306457B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114297698A (en) * 2021-12-29 2022-04-08 北京华大智宝电子系统有限公司 Data security processing method and device
CN116743371A (en) * 2023-07-19 2023-09-12 成都海泰方圆科技有限公司 Method and device for determining random number

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6628786B1 (en) * 1997-09-30 2003-09-30 Sun Microsystems, Inc. Distributed state random number generator and method for utilizing same
WO2012136763A2 (en) * 2011-04-05 2012-10-11 Intrinsic Id B.V. Random number generating system based on memory start-up noise
CN103294447A (en) * 2013-05-30 2013-09-11 华为技术有限公司 Method and device for generating random numbers
US20140059099A1 (en) * 2012-08-22 2014-02-27 International Business Machines Corporation Reducing bias in hardware generated random numbers
US9635011B1 (en) * 2014-08-27 2017-04-25 Jonetix Corporation Encryption and decryption techniques using shuffle function
CN107577452A (en) * 2016-07-04 2018-01-12 阿里巴巴集团控股有限公司 randomness detecting method and device
CN109683851A (en) * 2018-11-16 2019-04-26 深圳市先河系统技术有限公司 The generation method of random number, generating random number device, computer storage medium
WO2020009265A1 (en) * 2018-07-04 2020-01-09 주식회사 넘버스 Method and system for generating random numbers
CN110955407A (en) * 2019-11-21 2020-04-03 杭州趣链科技有限公司 Random number taking method based on block chain
CN111190570A (en) * 2018-11-15 2020-05-22 北京创原天地科技有限公司 High-quality random number generator and random number generation method

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6628786B1 (en) * 1997-09-30 2003-09-30 Sun Microsystems, Inc. Distributed state random number generator and method for utilizing same
WO2012136763A2 (en) * 2011-04-05 2012-10-11 Intrinsic Id B.V. Random number generating system based on memory start-up noise
US20140059099A1 (en) * 2012-08-22 2014-02-27 International Business Machines Corporation Reducing bias in hardware generated random numbers
CN103294447A (en) * 2013-05-30 2013-09-11 华为技术有限公司 Method and device for generating random numbers
US9635011B1 (en) * 2014-08-27 2017-04-25 Jonetix Corporation Encryption and decryption techniques using shuffle function
CN107577452A (en) * 2016-07-04 2018-01-12 阿里巴巴集团控股有限公司 randomness detecting method and device
WO2020009265A1 (en) * 2018-07-04 2020-01-09 주식회사 넘버스 Method and system for generating random numbers
CN111190570A (en) * 2018-11-15 2020-05-22 北京创原天地科技有限公司 High-quality random number generator and random number generation method
CN109683851A (en) * 2018-11-16 2019-04-26 深圳市先河系统技术有限公司 The generation method of random number, generating random number device, computer storage medium
CN110955407A (en) * 2019-11-21 2020-04-03 杭州趣链科技有限公司 Random number taking method based on block chain

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
JOHN VIEGA .ETC: "practical random number generation in software", 《19TH ANNUAL COMPUTER SECURITY APPLICATIONS CONFERENCE》, pages 1 - 12 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114297698A (en) * 2021-12-29 2022-04-08 北京华大智宝电子系统有限公司 Data security processing method and device
CN116743371A (en) * 2023-07-19 2023-09-12 成都海泰方圆科技有限公司 Method and device for determining random number
CN116743371B (en) * 2023-07-19 2024-07-23 成都海泰方圆科技有限公司 Method and device for determining random number

Also Published As

Publication number Publication date
CN112306457B (en) 2023-07-14

Similar Documents

Publication Publication Date Title
CN108023896B (en) Block synchronization method and system
CN112306457A (en) Random number generation method and device
CN108829518A (en) Method and apparatus for pushed information
CN105991282B (en) Password generated method and device
CN106650496A (en) Data processing method and device
CN103019929A (en) Computer software analysis system
CN111427691A (en) Virtual resource allocation method, device, medium and electronic equipment
CN111324591B (en) Block chain bifurcation detection method and related device
US20090217008A1 (en) Program conversion device, and secret keeping program
CN108932407B (en) Program safety protection method and device
JPWO2012131922A1 (en) Scheduling method and scheduling system
CN115269179A (en) A static memory allocation method, device, device and medium
CN114745363A (en) Method, system, device and medium for processing front-end application request message
KR101873879B1 (en) Data distribution storage apparatus and method using relative difference set generated from the group having the two-dimensional element
JP2022528254A (en) Methods and devices for fair lottery while reducing transaction costs using the blockchain network
KR101963821B1 (en) Method and apparatus for calculating similarity of program
CN113537392B (en) Method and device for identifying similar images, computing equipment and computer storage medium
CN113792247B (en) Method, apparatus, device and medium for generating functional flow chart based on code characteristics
CN111339523B (en) Authorization method and device for embedded equipment
CN108509773A (en) A kind of source code reinforcement means and device
CN112579046A (en) User story analysis method and device, electronic equipment and storage medium
CN116743371B (en) Method and device for determining random number
CN112380211A (en) Identification method and device for identity card number and electronic equipment
CN109634560A (en) Random digit generation method, device and storage medium
CN105824651B (en) A kind of smart card is interior to apply installation method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20220117

Address after: Unit 515, floor 5, building 1, No. a 12, Zhongguancun South Street, Haidian District, Beijing 100081

Applicant after: Shenzhou Rongan digital technology (Beijing) Co.,Ltd.

Address before: 100081 unit 408, 4th floor, building 1, a 12, Zhongguancun South Street, Haidian District, Beijing

Applicant before: SHENZHOU RONGAN TECHNOLOGY (BEIJING) CO.,LTD.

GR01 Patent grant
GR01 Patent grant
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载