Random number generation method, apparatus, computing device, and storage medium
Patent Information
- Application Number
- CN202510243325.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-28
- Publication Date
- 2026-08-28
AI Technical Summary
[0004]但是,上述介绍的熵源对硬件事件具有强依赖性,在部分硬件下会出现熵源不足的情况,这时会提供伪熵源,使得所生成的随机数的熵率较低,其质量无法满足高安全要求,甚至会出现卡顿现象
[0018] Based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods.
Smart Images

Figure CN122653569A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a random number generation method, apparatus, computing device, and storage medium. Background Technology
[0002] In encryption and decryption scenarios, random numbers play a crucial role, and their generation typically relies on entropy sources. Entropy sources can be categorized into two types: software entropy sources and hardware entropy sources. Hardware entropy sources usually depend on trusted platform module (TPM) chips. Within these chips, physical noise sources can generate highly random signals, which can then be used to further generate random numbers.
[0003] For software entropy sources, taking the Linux operating system as an example, the built-in / dev / random entropy source is typically used to generate random numbers. This entropy source mixes entropy sources such as the random jitter of the central processing unit (CPU) processing time, disk read / write operations, and hardware interrupts within the operating system, thereby providing random numbers to the outside world.
[0004] However, the entropy sources described above are highly dependent on hardware events. Under certain hardware conditions, the entropy source may be insufficient, leading to the provision of a pseudo-entropy source. This results in a low entropy rate for the generated random numbers, failing to meet high security requirements and potentially causing stuttering. Therefore, the entropy sources described above are insufficient to meet the requirements for high-quality and high-speed random numbers generated by entropy sources. Summary of the Invention
[0005] This application provides a random number generation method, apparatus, computing device, and storage medium capable of generating random numbers with high entropy rates, thereby meeting the requirements for high quality and high speed of random numbers generated from entropy sources. The technical solution is as follows.
[0006] In a first aspect, a random number generation method is provided, the method comprising: receiving a random number generation instruction, the random number generation instruction indicating the generation of a random number; responding to the random number generation instruction, executing multiple rounds of read-write events, the read-write events including a first read-write event and a second read-write event, the first read-write event being a read-write event for a first-level cache, and the second read-write event being a read-write event for a storage medium other than the first-level cache; and generating a random number based on the time consumed by the multiple rounds of read-write events.
[0007] During each read / write event, the location hit is random and unpredictable. The time difference between hitting the first-level cache and hitting storage media other than the first-level cache is significant, as are the time differences between different read / write events and even between multiple rounds of read / write events. After obtaining the time of each round of read / write events, entropy is calculated for each round to obtain random numbers. The significant differences in time between multiple rounds of read / write events increase the unpredictability of the extracted entropy, which improves the entropy rate of the random numbers and the quality of the random numbers generated by the entropy source. Furthermore, while ensuring an increased entropy rate, the generation rate of high-quality random numbers also increases accordingly. This helps meet the high-speed requirement for random numbers generated by the entropy source, thus satisfying the random number needs of subsequent processes.
[0008] In some embodiments, the storage medium other than the first-level cache is a second-level cache or memory. This application does not limit the storage medium other than the first cache, allowing for more flexible execution of read and write events, which is beneficial for improving the entropy rate of random numbers, thereby meeting the requirements for high quality and high speed of random numbers.
[0009] In some embodiments, the above-described execution of multiple rounds of read / write events includes: when executing the i-th read / write event in the n-th round of read / write events, determining the read / write position of the i-th read / write event based on the system time corresponding to the n-th round of read / write events; and executing the i-th read / write event based on the read / write position, where n is a positive integer greater than or equal to 1, and i is a positive integer greater than or equal to 1. Using system time provides randomness to the determination of subsequent read / write positions, which increases the uncertainty of read / write event latency and helps improve the quality of generated random numbers.
[0010] In some embodiments, the above-described execution of multiple rounds of read / write events includes: when executing any read / write event in the nth round of read / write events, determining the read / write position and written content of the read / write event based on the system time corresponding to the nth round of read / write events; and executing the read / write event based on the read / write position and written content, where n is a positive integer greater than or equal to 1. Using the read / write position and written content determined by the system time to jointly guide the execution of read / write events makes the read / write process more unpredictable, which is beneficial for improving the quality of subsequently generated random numbers.
[0011] In some embodiments, determining the read / write position of the read / write event based on the system time corresponding to the nth round of read / write events includes: when i is greater than or equal to 2, determining the read / write position of the i-th read / write event based on the system time corresponding to the nth round of read / write events and the read / write value of the (i-1)th read / write event. By determining the read / write position using the system time and read / write value, the system time and read / write value provide randomness and uncertainty, thus the change in the read / write position also possesses randomness. This increases the uncertainty of the read / write event's latency, which is beneficial for generating high-quality random numbers.
[0012] In some embodiments, generating random numbers based on the time consumed by the multiple rounds of read / write events includes: if the generated random number fails the entropy quality detection, adjusting at least one of the entropy taking position and the number of read / write events, where the number of read / write events is the number of occurrences of read / write events in each round of read / write events; and regenerating random numbers based on the adjusted entropy taking position and the number of read / write events. This dynamic adjustment facilitates adaptation to different CPU read / write speeds, thereby avoiding compatibility issues between different CPUs and ensuring the stability of random number generation. This method significantly reduces the impact of CPU clock precision on random number generation, improves compatibility across different hardware configurations, and not only provides higher random number generation rates and higher quality and more stable entropy for high-precision CPU clocks, but also avoids generally poor quality and low entropy rates in the generated random numbers for low-precision CPU clocks, thus preventing problems such as failure to meet subsequent application requirements.
[0013] In some embodiments, adjusting at least one of the entropy taking position and the number of read / write operations includes any one of the following: increasing the number of read / write operations; moving the entropy taking position backward; moving the entropy taking position backward and resetting the number of read / write operations to the initial number. By flexibly and adaptively adjusting at least one of the entropy taking position and the number of read / write operations, it is easier to determine suitable data that can guarantee entropy rate and performance, thereby ensuring the generation of high-quality random numbers.
[0014] Secondly, a random number generation apparatus is provided for performing the above-described random number generation method. Specifically, the random number generation apparatus includes a functional module for performing the random number generation method provided in the first aspect or any alternative method of the first aspect.
[0015] Thirdly, a computing device or cluster of computing devices is provided, the computing device including a processor for executing program code, causing the computing device or cluster of computing devices to perform operations as described above in the random number generation method.
[0016] Fourthly, a computer-readable storage medium is provided, which stores at least one piece of program code that is read by a processor to cause a computing device to perform operations as described in the random number generation method above.
[0017] Fifthly, a computer program product or computer program is provided, the computer program product or computer program including program code stored in a computer-readable storage medium, a processor of a computing device reading the program code from the computer-readable storage medium, the processor executing the program code, causing the computing device to perform the method provided in any of the first and second aspects or various alternative implementations of any of the aspects.
[0018] Based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods. Attached Figure Description
[0019] Figure 1 This is a schematic diagram illustrating an application scenario of random numbers provided in an embodiment of this application;
[0020] Figure 2 This is a flowchart of a random number generation method provided in an embodiment of this application;
[0021] Figure 3 This is a schematic diagram of the read / write position in a read / write event provided in an embodiment of this application;
[0022] Figure 4 This is a schematic diagram of a random number generation process provided in an embodiment of this application;
[0023] Figure 5 This is a flowchart illustrating a random number application provided in an embodiment of this application;
[0024] Figure 6 This is a schematic diagram of the structure of a random number generation device provided in an embodiment of this application;
[0025] Figure 7 This is a schematic diagram of a system architecture provided in an embodiment of this application;
[0026] Figure 8 This is a schematic diagram of the structure of a computing device provided in an embodiment of this application. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings. It should be noted that all information and data involved in this application are authorized by the user or fully authorized by all parties, and the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, timestamps, memory values, etc., involved in this application are obtained under fully authorized conditions.
[0028] To facilitate understanding, the key terms and concepts involved in this application will be explained below.
[0029] Entropy is a measure of the disorder, randomness, or variability of a closed system. Higher entropy indicates greater uncertainty; lower entropy indicates less uncertainty.
[0030] An entropy source is the origin of random numbers; it can be a component, device, or event that generates the output. Through specific capture and processing mechanisms, bit strings containing entropy can be extracted from the output of an entropy source. These bit strings can be used as random numbers or as seeds for a random number generator. For example, entropy sources include noise generated by hardware devices, system clock jitter, and user input.
[0031] A random number generator (RNG) is a device or program that can generate random bit sequences.
[0032] A random number seed is a string of bits used as input to a random number generator.
[0033] A deterministic random number generator (DRNG) is a random number generator that generates random bit sequences based on a random number seed and a deterministic algorithm. Given the same random number seed, a deterministic random number generator will generate the same bit sequence.
[0034] CPU jitter refers to the uncertainty and fluctuation in the time consumed by the CPU to perform memory read and write operations due to the complexity of modern operating systems and the scheduling effects of various hardware components, such as multi-task scheduling mechanisms, hardware resource competition, and various interrupt events. This inconsistency in time consumption is called CPU jitter.
[0035] CPU jitter entropy sources refer to entropy sources that utilize the random event of inconsistent time consumption (i.e., CPU jitter) during CPU memory read and write operations to generate output. By capturing and processing relevant CPU jitter data, bit strings containing entropy can be extracted and used as random numbers or random number seeds.
[0036] The following section introduces the application scenarios of random numbers. Figure 1 This is a schematic diagram illustrating an application scenario for random numbers provided in an embodiment of this application. In this application scenario, a CPU jitter entropy source and other possible entropy sources are provided. Optionally, the random numbers generated by the CPU jitter entropy source can be used alone, or they can be mixed with random numbers generated by other entropy sources before use. The random numbers generated by the aforementioned entropy sources can be provided directly or indirectly to applications for use.
[0037] This application does not limit the method of mixing random numbers generated by CPU jitter entropy sources and other entropy sources. For example, for random numbers generated by CPU jitter entropy sources and other entropy sources, entropy source mixing can be achieved through at least one of several processing methods, such as direct concatenation, XOR operation, and hash operation. Entropy source mixing can combine the randomness of multiple entropy sources, resulting in a higher entropy rate of the generated random numbers.
[0038] In one possible implementation, the random numbers generated by the entropy source are directly provided to the application. That is, the application uses the random numbers generated by the entropy source to implement subsequent random events. For example, encryption and decryption keys can be created based on the random numbers generated by the entropy source to implement encryption and decryption services, ensuring data security. The high randomness of these random numbers makes the resulting keys unpredictable, effectively increasing the security of encrypted data. Another example is an online examination system where questions are drawn from a question bank and given to the user, with different random numbers pre-defined to correspond to different questions in the question bank. When the application runs, it draws the question corresponding to the random number generated by the entropy source and gives it to the user. Yet another example is a card-drawing function where virtual resources are provided to the user in response to the card-drawing operation, with different ranges of random numbers pre-defined to correspond to different virtual resources. When the application runs, in response to the card-drawing operation, it obtains the random number generated by the entropy source and determines the corresponding virtual resource as the card-drawing result based on the range of that random number. In another possible implementation, the data generated by the random numbers generated by the entropy source is further provided to the application. In other words, the random numbers generated by the entropy source are used as random number seeds and input into the random number generation algorithm to obtain new random numbers. The application uses these new random numbers to realize various random events or random scenarios.
[0039] For ease of description, we will use the example of random numbers generated by a combination of CPU jitter entropy sources and other entropy sources. See [link to documentation]. Figure 1 As shown. After the entropy source mixing is complete, the application reads the generated random number as the basis for subsequent processing. Optionally, this random number is directly provided to the application, as described in the first possible implementation above. Alternatively, the random number is indirectly provided to the application, processed by relevant algorithms in the cryptographic module to generate new random numbers. These new random numbers can be directly provided to the application or used as keys for cryptographic algorithms in the cryptographic module, thereby implementing encryption and decryption services in the application. The cryptographic module includes algorithms related to random number applications in high-security scenarios. The encryption and decryption services here include encrypting and decrypting data within the application.
[0040] The above example illustrates the mixing of random numbers generated by CPU jitter entropy source and other entropy sources. The principle of using CPU jitter entropy source alone is the same, and will not be repeated here.
[0041] This application applies to scenarios involving CPU jitter entropy sources generating random numbers. Because traditional entropy sources generate random numbers at a low rate, they cannot promptly meet the random number requirements of subsequent applications, potentially causing system lag. Therefore, optimizing the random number generation rate of traditional entropy sources is essential.
[0042] Taking the ` / dev / random` entropy source built into the Linux operating system as an example, this entropy source is a multi-entropy source, including the CPU jitter entropy source. Currently, the main approach to solving the system lag problem caused by this entropy source is to improve the processing mechanism for generating random numbers using the CPU jitter entropy source. For example, one method is to generate candidate bits based on clock time, update these candidate bits through a series of processes, and use von Neumann unbiased analysis to determine whether to retain the updated candidate bits. If retained, these are identified as random bits included in the random number, and the above process is repeated to obtain the random number. Another method is to obtain the time taken for multiple memory reads and writes based on the CPU clock, use this time as input to a hash algorithm, and then use the hash algorithm to obtain a random number.
[0043] For the first method, since it relies on reading and writing to the L1 cache to obtain the time difference, and then updates the candidate bits using the data related to this time difference, the fluctuation of the time difference generated by reading and writing to the L1 cache is very small, resulting in low randomness of the obtained candidate bits and thus a low entropy rate of the random numbers. Furthermore, the updating and analysis process of candidate bits is relatively complex, which has a certain impact on overall performance. For the second method, since it depends on the precision of the CPU clock, its versatility is poor. If the CPU clock precision is low, the fluctuation between the multiple acquisition times will be small, resulting in a low entropy rate of the random numbers. This method is basically unusable with low-precision CPU clocks. Additionally, the hash operation in this method has a large time overhead, which affects overall performance.
[0044] Therefore, while the aforementioned methods improve the rate of random number generation by the entropy source to some extent, the entropy rate of the generated random numbers is still low. The rate at which the entropy source generates high-quality random numbers still cannot meet the needs of subsequent applications and cannot solve the problem of potential system lag. Based on this, this application provides a random number generation method that improves the entropy rate of random numbers generated by the CPU entropy source, enhances the quality of the generated random numbers, and further, while ensuring a higher entropy rate, significantly increases the probability of random numbers meeting quality requirements. This improves the rate at which the entropy source generates usable random numbers, meets the high-rate requirement for random number generation by the entropy source, and can significantly reduce system lag and other problems caused by low random number generation rates.
[0045] The random number generation method proposed in this application will be briefly introduced below.
[0046] In this method, multiple read / write events are executed to generate random numbers. These read / write events are not limited to a single cache level; they can hit other caches besides those mentioned above, and even memory. That is, multiple read / write events can include read / write events targeting multiple cache levels, or read / write events targeting both cache and memory. Since the location hit in each read / write event is random and unpredictable, and the time difference between read / write operations when hitting different caches or memory is significant, the time difference between different read / write events is substantial. After obtaining the time of each round of read / write events, entropy is taken from the time of each round to further obtain random numbers. With a large difference in the time of multiple rounds of read / write events, the unpredictability of the extracted entropy also increases, which improves the entropy rate of the random numbers. The probability of the random numbers meeting the quality requirements is also greatly increased, thereby improving the rate at which the entropy source generates random numbers. This meets the requirements for high quality and high speed of random numbers generated by the entropy source, reducing system stuttering and other problems caused by low random number generation rates.
[0047] To achieve the above effects, a two-dimensional row-column read / write method is designed. In this method, multiple rounds of cyclic read / write operations are performed on the two-dimensional row-column memory. Each round of cyclic read / write operations on the two-dimensional row-column memory includes multiple read / write events, and the time consumed by each round of cyclic read / write events is obtained. Random numbers are generated based on the time consumed by the multiple rounds of read / write events. The read / write events include read / write events targeting the first-level cache and read / write events targeting storage media other than the first-level cache. Storage media other than the first-level cache are the second-level cache or memory. This application embodiment does not limit the first-level cache and the second-level cache; they can be different. It should be noted that this application embodiment uses hitting the first-level cache and the second-level cache as examples for illustration, but it is not limited to this. This application embodiment also supports hitting more levels of cache, such as the third-level cache. Taking the first-level cache as the L1 cache as an example, the second-level cache includes L2 cache and L3 cache, etc. Each read / write event randomly hits two-dimensional row and column memory, and the time difference when hitting different caches or memory is large. This provides more randomness for random number generation, which is conducive to improving the entropy rate, thereby improving the generation rate of high-quality random numbers and meeting the requirements for high quality and high speed of random numbers.
[0048] To further enhance randomness, system time is introduced to determine the read / write position during multiple rounds of read / write events, thus executing each read / write event. System time refers to the current time obtained from the CPU clock before executing a round of read / write events. The read / write position can be represented by read / write indexes or memory block read coordinates, etc. Different rounds of read / write events correspond to different system times, which provides additional randomness to the random number generation process, further improving the quality of random numbers and thus increasing the random number generation rate. Furthermore, using the read / write position and the content written to execute read / write events adds even more unpredictability, increasing the entropy rate of the generated random numbers. When executing any read / write event, if the read / write position is determined based on the system time and the read / write value of the previous event, the change in the read / write position becomes even more unpredictable. This further enhances the randomness in read / write events, increases the entropy rate of the generated random numbers, and helps meet the high-quality requirements for random numbers.
[0049] After generating random numbers as described above, an entropy quality check is performed to determine if the generated random numbers meet the quality requirements. If the generated random numbers fail the entropy quality check, at least one of the entropy retrieval position and the number of read / write operations is adjusted. Based on the adjusted entropy retrieval position and the number of read / write operations, random numbers are regenerated. Different entropy retrieval positions indicate different time precisions; lower entropy retrieval positions correspond to smaller time units, and higher entropy retrieval positions correspond to larger time units. Based on this adaptive digitization method, when the entropy retrieved at an entropy retrieval position corresponding to a certain time precision fails to meet the quality requirements, dynamic adjustment allows entropy to be retrieved at entropy retrieval positions corresponding to other time precisions to generate random numbers. This facilitates adaptation to different CPU read / write speeds, thereby avoiding compatibility issues between different CPUs and ensuring the stability of random number generation.
[0050] Through the aforementioned two-dimensional row-column read / write method and adaptive digitization processing, on the one hand, entropy is collected in two-dimensional space, and a certain randomness algorithm is used in conjunction with system time to obtain random read / write positions. This allows for hitting different caches or memory, thereby achieving a larger time difference, increasing randomness, and improving the entropy rate of random numbers. On the other hand, the number of read / write operations and the entropy retrieval position are dynamically adjusted to ensure compatibility with CPUs of different read / write speeds. This adaptive digitization processing method continues during startup and operation, significantly reducing the impact of CPU clock precision on random number generation and improving compatibility across different hardware configurations. It not only provides a higher random number generation rate and higher quality and more stable entropy for high-precision CPU clocks, but also avoids generally poor quality and low entropy rates for low-precision CPU clocks, ensuring high availability. Compared to the traditional method that calls a hash algorithm, this method does not require calling other algorithms, reducing performance overhead. In summary, this method ensures higher entropy rate random number generation while significantly increasing the probability of random numbers meeting quality requirements. This improves the rate at which the entropy source generates usable random numbers, meeting the high-rate requirement for random number generation. It can greatly reduce system lag and other issues caused by low random number generation rates. The random numbers generated by this method can be applied to scenarios with high security requirements, such as identity recognition and blockchain, or authentication scenarios. It can effectively replace hardware entropy sources, thereby saving costs.
[0051] Having briefly introduced the random number generation method proposed in this application above, the detailed process of this random number generation method is described below. For example... Figure 2 As shown, Figure 2 This is a flowchart of a random number generation method provided in an embodiment of this application. The description uses a computing device, which includes a CPU, as an example to illustrate the random number generation method. The method includes the following steps:
[0052] 201. The computing device receives a random number generation instruction, which instructs the generation of random numbers.
[0053] 202. The computing device responds to the random number generation command and executes multiple rounds of read and write events.
[0054] The read / write events include a first read / write event and a second read / write event. The first read / write event is a read / write event targeting the first-level cache, and the second read / write event is a read / write event targeting storage media other than the first-level cache. Storage media other than the first-level cache can include various storage media such as the second-level cache or memory. The second-level cache can include multiple levels of cache. For example, the first-level cache is L1 cache, the second-level cache includes at least one of L2 cache and L3 cache, and the memory is double data rate (DDR) memory. The above-described read / write events hitting the first and second-level caches are merely illustrative examples; the embodiments of this application are not limited to these and can also hit more levels of cache, such as the third-level cache.
[0055] The following explanation uses the nth round of read / write events in the above multi-round read / write events as an example, where n is a positive integer greater than or equal to 1. During the execution of the nth round of read / write events, the computing device performs the following steps (1)-(4).
[0056] (1) The computing device obtains the system time corresponding to the nth round of read / write events, which is the start timestamp of the nth round of read / write events. Accordingly, before executing the nth round of read / write events, the computing device obtains the current system time from the CPU clock as the start timestamp, denoted as time1.
[0057] (2) The computing device executes each read / write event based on the above system time.
[0058] The following explanation uses the i-th read / write event in the n-th round of read / write events as an example, where i is a positive integer greater than or equal to 1.
[0059] In one possible implementation, the computing device determines the read / write position of the i-th read / write event based on the system time corresponding to the n-th round of read / write events; based on the read / write position, it executes the i-th read / write event. The system time provides randomness to the determination of subsequent read / write positions, increasing the uncertainty of read / write event latency and thus improving the quality of random numbers. In another possible implementation, the computing device determines the read / write position and write content of the i-th read / write event based on the system time corresponding to the n-th round of read / write events; based on the read / write position and write content, it executes the read / write event. The read / write position and write content determined by the system time jointly guide the execution of the read / write event, making the read / write process more unpredictable and thus improving the generation of high-quality random numbers.
[0060] The following is an exemplary read / write process. The computing device determines memory read / write coordinates based on the aforementioned system time, and then determines a random initial read / write value based on these coordinates. These coordinates indicate the position of the initial read / write value, which is the memory value read from these coordinates. The next read / write position is determined based on this value. This method, combined with conditional judgments (such as different read / write value ranges corresponding to different read / write position determination rules), prevents CPU branch prediction, i.e., prevents the CPU from accurately predicting subsequent read / write positions. This ensures that subsequent read / write positions are unpredictable to the CPU, thereby increasing the unpredictability of the read / write process. The read / write value is then XORed and added, and the resulting value is written to the determined new read / write position. Based on this value and a preset step size, the next read / write position is determined for the next read / write operation. This read / write method combines system time, read / write values, and a preset step size, increasing the randomness of read / write events, which helps to increase the fluctuation of read / write event latency and improves the entropy rate of subsequently generated random numbers.
[0061] For the above-mentioned multiple possible implementation methods, when i is 1, the read / write position of the first read / write event is determined based on the system time corresponding to the nth round of read / write events; when i is greater than or equal to 2, the read / write position of the i-th read / write event is determined based on the system time corresponding to the nth round of read / write events and the read / write value of the (i-1)th read / write event.
[0062] The following is an exemplary method for determining the read / write location of the i-th read / write event when i is greater than or equal to 2. The read / write location is represented by memory read / write coordinates. The computing device determines the read / write index of the i-th read / write event based on the system time, the read / write value of the (i-1)-th read / write event, the fixed step size, the capacity of the L1 cache, and the data size of the minimum cache unit. Based on the read / write index and the data size of the minimum cache unit, the row and column indices in the memory read / write coordinates are determined. These memory read / write coordinates indicate the memory block that is read / written during the i-th processing step, which is located in the L1 cache or in other storage media besides the L1 cache.
[0063] For clarity in describing the exemplary determination method described above, please refer to [link to relevant documentation]. Figure 3 As shown, Figure 3This is a schematic diagram illustrating the read / write location in a read / write event according to an embodiment of this application. The upper row limit of the memory block's range is the sum of the ratio between the capacity of the first-level cache and the data size of the smallest cache unit, and a preset value; the upper column limit of the memory block's range is the data size of the smallest cache unit. For example, the upper row limit of the memory block's range is (L1 cache size / cache line) + a preset value; the upper column limit of the memory block's range is cache line. Here, L1 cache size represents the capacity of the first-level cache, and cache line represents the smallest cache unit. In this case, the object of the two-dimensional row-column read / write is the heap memory defined by the aforementioned upper row and column limits, and the total capacity of this heap memory, cache size, is ((L1 cache size / cache line) + 1) * cache line. Correspondingly, the read / write index of the i-th read / write event is the remainder of the sum of the aforementioned system time, the read / write value of the i-th read / write event, and the fixed step size divided by the capacity of the first-level cache. In the memory read / write coordinates, the row index is the integer result of the ratio between the read / write index and the data size of the smallest cache unit, and the column index is the result of the read / write index modulo the data size of the smallest cache unit. That is, the read / write index is represented as (system time + read / write value of the last read / write event + fixed step size) % cache size, and the row and column indices in the memory read / write coordinates are read / write index / cache line and read / write index % cache line, respectively. Here, " / " indicates division, "*" indicates multiplication, and "%" indicates modulo operation.
[0064] It should be noted that, since this application employs a randomized algorithm strategy during the two-dimensional row and column read and write process, and combines system time to execute each read and write event, this not only ensures the randomness of each read and write position, but also ensures that the storage medium other than the first-level cache is hit within each round of read and write operations. This provides more time fluctuations, increases randomness, and improves the entropy rate of random numbers, thereby meeting the requirements for high quality and high speed of random numbers.
[0065] (3) When a read / write event is completed, the computing device determines whether the number of read / write events executed in the nth round of read / write events has reached the first read / write count, which is the number of read / write events required in the nth round of read / write events.
[0066] If the first read / write count is recorded as x, then after the i-th read / write event is completed, the computing device determines whether i is equal to x. It should be noted that this determination step is optional. In the actual execution process of the computing device, this determination step may not exist, and the computing device may directly execute the following step (4).
[0067] (4) If the number of read and write events has reached the first read and write count, the computing device obtains the end timestamp of the nth round of read and write events. Based on the above start timestamp and end timestamp, the time consumption of the nth round of read and write events is determined. The time consumption is the difference between the start timestamp and the end timestamp.
[0068] That is, when i equals x, since the number of read / write events has reached the first read / write count, the nth round of read / write events has ended. Therefore, the computing device obtains the current timestamp from the CPU clock as the end timestamp, denoted as time2, and thus determines the time consumption of the nth round of read / write events, denoted as delta = time2 – time1. Conversely, if the number of read / write events has not yet reached the first read / write count, the computing device executes the (i+2)th read / write event. That is, when i is still less than x, since the number of read / write events has not yet reached the first read / write count, the nth round of read / write events has not yet ended. Therefore, the computing device executes the (i+1)th read / write event according to the above step (2), and continues to execute subsequent steps, looping until the nth round of read / write events ends.
[0069] 203. The computing device obtains a preset number of entropies based on the time consumed by multiple rounds of read and write events. The preset number of entropies includes the entropy taken from the first entropy taking position in the time consumed by each round of read and write events.
[0070] Since entropy quality detection requires determining whether a given amount of entropy meets the requirements in a batch, entropy quality detection is performed on these entropies once they have accumulated to the preset amount. Correspondingly, a preset number of read / write events are executed repeatedly to obtain the time consumed by these preset number of read / write events. Here, the preset amount can be represented as the window size, i.e., the amount of entropy accumulated in one cycle (window size).
[0071] The above explanation uses the execution of the nth round of read / write events as an example. Below are two exemplary methods for the computing device to proceed after the nth round of read / write events has concluded, as shown in Method (I) and Method (II).
[0072] Method (1): The computing device determines whether to execute the (n+1)th round of read / write events based on the amount of entropy already retrieved. Accordingly, after the execution of the nth round of read / write events, the computing device retrieves entropy from the time consumed by the nth round of read / write events according to the first entropy retrieval position. After the above entropy retrieval process is completed, the computing device determines whether a preset amount of entropy has been obtained. If the amount of entropy retrieved from the time consumed by the 1st to nth rounds of read / write events has reached the preset amount, it means that the preset amount of entropy has been obtained, and random numbers are generated based on this entropy. If the amount has not yet reached the preset amount, it means that the preset amount of entropy has not yet been obtained, and the (n+1)th round of read / write events is executed. In this way, even if an anomaly occurs during a particular entropy retrieval process, it can ensure that the preset amount of entropy has indeed been obtained, effectively avoiding the impact on entropy quality detection and other processes, and improving the reliability of random number generation.
[0073] Method (II): The computing device determines whether to execute the (n+1)th round of read / write events based on the round number of read / write events. Correspondingly, after the nth round of read / write events has ended, the computing device determines whether a preset number of rounds of read / write events have been completed. If n equals the preset number, it means that the preset number of rounds of read / write events have been executed, and the computing device extracts entropy from the time consumed by the nth round of read / write events according to the first entropy extraction position. If n is still less than the preset number, after the computing device extracts entropy from the time consumed by the nth round of read / write events according to the first entropy extraction position, it continues to execute the (n+1)th round of read / write events. This method directly determines whether the entropy extraction operation can be terminated based on the round number, making it more intuitive and convenient, and resulting in higher overall processing efficiency.
[0074] 204. The computing device performs entropy quality detection on a preset number of entropies.
[0075] This application does not limit the method used for entropy quality detection; those skilled in the art can choose and set it as they see fit. For example, entropy quality detection methods include the adaptive proportion test (APT) and the repeat count test (RCT). The adaptive proportion test dynamically adjusts the detection threshold or parameters to accurately assess whether the proportion of various elements in the random numbers meets the requirements of randomness. The repeat count test groups the random numbers according to a specific length, counts the number of occurrences of the same number combination in each group, compares it with the expected number, and then determines whether the randomness of the random numbers meets the requirements.
[0076] 205. If a preset amount of entropy passes the entropy quality test, a random number composed of the preset amount of entropy is determined.
[0077] Optionally, after generating random numbers, the computing device can end the current random number generation process or continue generating random numbers. If the random number generation instruction indicates that a random number including a preset amount of entropy should be generated, the computing device can end the current process; if the random number generation instruction indicates that the amount of entropy included in the generated random number is greater than the preset amount, the random number obtained after executing step 205 still cannot meet the requirements of the random number generation instruction. Therefore, the computing device continues to generate random numbers according to steps 202 to 205 above.
[0078] In one possible implementation, if a preset number of entropies pass the entropy quality test, it indicates that the entropy determined based on the current number of read / write operations and the entropy retrieval position meets the quality requirements. The computing device records the number of read / write operations and the entropy retrieval position. When generating random numbers subsequently, the computing device directly generates random numbers based on the recorded number of read / write operations and the entropy retrieval position. This method improves the efficiency of subsequent random number generation.
[0079] 206. If the preset number of entropies fails the entropy quality test, adjust at least one of the first entropy taking position and the first read / write count, and regenerate random numbers according to the adjusted data.
[0080] In this embodiment, there are no restrictions on the adjustment method for at least one of the first entropy position and the first read / write count. Three exemplary adjustment methods are given below: Method A, Method B, and Method C.
[0081] Method A: The computing device increases the number of read / write operations. Accordingly, based on the first number of read / write operations and a preset adjustment value, the computing device determines a second number of read / write operations, which is the sum of the first number of read / write operations and the preset adjustment value. The preset adjustment value is a positive integer. Since the adjusted second number of read / write operations is greater than the original first number of read / write operations, and the time consumed by each read / write event includes a certain degree of randomness, the time consumed by performing a round of read / write events according to the second number of read / write operations contains more randomness than the time consumed by performing a round of read / write events according to the first number of read / write operations. This facilitates the generation of higher-quality random numbers subsequently.
[0082] Method B: The computing device moves the entropy taking position backward. Correspondingly, based on the first entropy taking position and a preset position adjustment value, the computing device determines a second entropy taking position, which is the sum of the first entropy taking position and the preset position adjustment value. The preset position adjustment value is either a positive or negative integer. The entropy taking position indicates that entropy is taken starting from the least significant bit; that is, when the time consumption is represented as a binary bit string, the entropy taking position indicates that entropy is taken starting from the right side of the bit string. For example, if the entropy taking position is the 3rd bit, then the 3rd bit from the rightmost bit in the bit string is taken as the entropy. When the time consumption is represented as a binary bit string, the precision decreases from the least significant bit to the most significant bit; that is, the least significant bit represents a smaller time unit, and the most significant bit represents a larger time unit. Therefore, if the entropy obtained at a certain time unit cannot meet the requirements for entropy quality detection, the entropy is adjusted to another position corresponding to that time unit, or to another position corresponding to a different time unit, thereby obtaining entropy that meets the requirements for entropy quality detection.
[0083] Method C: The computing device moves the entropy retrieval position backward and resets the read / write count to the initial count. Correspondingly, based on the first entropy retrieval position and the preset position adjustment value, the computing device determines the second entropy retrieval position and resets the first read / write count to the preset initial value. By adjusting the entropy retrieval position and resetting the first read / write count to the preset initial value, high-quality entropy is easily obtained while keeping the time consumed in each round of read / write events relatively small.
[0084] In one possible implementation, the computing device selects different adjustment methods under different circumstances. For example, the computing device preferentially adjusts according to method A, determining the second read / write count based on the first read / write count and a preset adjustment value. If the second read / write count is less than the preset threshold, the computing device re-executes multiple rounds of read / write events according to the second read / write count and the first entropy position, obtaining a preset number of entropies. If the second read / write count is not less than the preset threshold, the computing device adjusts according to method C, determining the second entropy position based on the first entropy position and a preset position adjustment value, and resetting the read / write count to the preset initial value. By dynamically adjusting the read / write count and entropy position, an entropy that meets quality requirements can be determined while ensuring that the time consumption of each round of read / write events is not too long. This adaptive digital processing method can greatly reduce the impact of CPU clock precision on random number generation, improve compatibility on different hardware configurations, and ensure the versatility of this method.
[0085] To facilitate a further explanation of the above detailed process, examples are provided below to illustrate aspects such as the entropy retrieval location, number of reads, and preset quantity. See [link to relevant documentation]. Figure 4 As shown, Figure 4This is a schematic diagram of a random number generation process provided in an embodiment of this application. The data settings are as follows: initial number of iterations is 40, preset number of iterations adjustment value is 40, preset number of iterations threshold is 1024, initial value of entropy position is 3, upper limit value of entropy position is 6, preset position adjustment value is 1, and preset quantity is 1024.
[0086] The following describes a series of processing steps based on the data settings described above. In short, see [link to documentation]. Figure 4 As shown in Figure (a), the computing device first performs two-dimensional row and column read / write operations according to step 202, and counts the time consumed by a preset number of cyclic read / write events. Then, the computing device performs adaptive digitization processing according to step 203, obtaining a preset number of entropies. Afterwards, the computing device performs entropy acquisition and entropy detection. Accordingly, the computing device performs 40 read / write events, obtains the time consumed in this process, and takes the 3rd bit from this time as 1 bit of entropy. The above process is repeated 1024 times to obtain 1024 bits of entropy. If the 1024 bits of entropy pass the entropy quality detection, a 1024-bit random number is obtained. If the 1024 bits of entropy fail the entropy quality detection, at least one of the read / write count and the entropy acquisition position is adjusted, and 1024 bits of entropy are acquired again.
[0087] More specifically, see Figure 4As shown in Figure (b), in response to the received random number generation instruction, the computing device executes step 401 to obtain the start timestamp of the first round of read / write events. The computing device executes 40 read / write events according to the number of read / write events corresponding to the first round (i.e., the initial number). During this process, step 402 is executed first, performing one read / write event based on the start timestamp; then step 403 is executed to determine whether 40 read / write events have been performed. If 40 read / write events have not been performed, step 402 is executed to perform the next read / write event; if 40 read / write events have been performed, step 404 is executed to obtain the end timestamp of the first round of read / write events and determine the duration of the first round of read / write events, which is the difference between the start and end timestamps. Then, the computing device executes step 405, extracting the third bit from the least significant bit of the duration of the first round of read / write events as 1 bit of entropy, based on the initial value of the entropy position. The computing device executes step 406 to determine whether 1024 bits of entropy have been accumulated, i.e., whether 1024 rounds of read / write events have been executed. If 1024 bits of entropy have not been accumulated, execution continues from step 402 to proceed to the next round of read / write events; if 1024 bits of entropy have been accumulated, step 407 is executed to perform entropy quality detection on these entropies. After executing step 407, the computing device executes step 408 to determine whether these entropies pass the entropy quality detection. The subsequent processing flow differs depending on the determination result. If the entropy quality detection passes, these entropies are used as the generated 1024-bit random number; if the entropy quality detection fails, step 409 is executed to adjust the read / write count, i.e., the read / write count is increased by 40. When the read / write count reaches a preset number, the number of bits for entropy retrieval is adjusted, and the read / write count is reset to the initial count. That is, when the read / write count reaches 1024, the number of bits for entropy retrieval is incremented by 1, and the read / write count is reset to 40. After executing step 409, the computing device re-executes from step 401 to continue generating the next 1024-bit random number.
[0088] Building upon the random number generation methods described above, the usage of the generated random numbers is further explained. In one possible implementation, the generated random numbers are applied in real-time after a preset amount of entropy passes entropy quality testing. For example, the random numbers can be provided to subsequent applications or input into subsequent random number generation algorithms to generate new random numbers, thus improving overall efficiency. In another possible implementation, the generated random numbers are temporarily stored after a preset amount of entropy passes entropy quality testing. For example, the random numbers can be stored in a CPU jitter entropy pool for easy retrieval. When subsequent applications or random number generation algorithms require random numbers, the corresponding amount of entropy can be retrieved from this pool, improving the convenience of random number application. In this possible implementation, a threshold can be set for the amount of entropy in the CPU jitter entropy pool. When the amount of entropy in the pool falls below this threshold, a random number generation instruction is generated, and random numbers are generated cyclically according to the random number generation method provided in this application, and stored in the entropy pool until the amount of entropy in the pool reaches the upper limit, at which point generation and storage cease.
[0089] The following explanation uses the example of storing generated random numbers in a CPU jitter entropy pool and subsequently applying them to a random number generation algorithm. Since the random number generation algorithm has further quantity and quality requirements for the input random number seed, entropy is retrieved from the CPU jitter entropy pool and compressed according to an entropy compression ratio to obtain full-entropy data that meets the quality requirements. The entropy compression ratio is either a preset ratio or a ratio obtained through detection; this embodiment does not impose any limitations on this. The full-entropy data is stored in a full-entropy pool. During the random number generation algorithm's execution, full-entropy data meeting the quantity requirements is retrieved from the full-entropy pool and input into the algorithm to generate new random numbers. In the above scenario, a quantity threshold can be set for the number of full-entropy data in the full-entropy pool. If the number of full-entropy data in the pool is lower than this threshold, full-entropy data is replenished from the CPU jitter entropy pool according to the random number generation method provided in this application until the number of full-entropy data in the pool reaches its upper limit, at which point replenishment stops.
[0090] To further illustrate the above examples, the following examples explain the quantity requirements, entropy compression ratio, quantity threshold, and upper limit. See [link to relevant documentation]. Figure 5 As shown, Figure 5 This is a flowchart illustrating a random number application provided in an embodiment of this application. See also... Figure 5As shown in Figure (a), for the generated random numbers, entropy source compression is performed first, followed by random number generation. The data settings are as follows: the input quantity requirement is 32 bytes of full entropy data, the entropy compression ratio is 1 / 4, and the quantity threshold is half of the upper limit, with the upper limit being 4096 bytes. When the amount of full entropy data in the entropy pool falls below half its capacity, data replenishment is triggered until the entropy pool is replenished to 4096 bytes.
[0091] Since the random numbers generated by the CPU jitter entropy source can be used independently by the random number generation algorithm, or they can be used together with random numbers generated by other entropy sources, these two usage methods will be described separately under the above data settings. See also Figure 5 As shown in Figure (b), when the random number generated by the CPU jitter entropy source is used as the random number seed for the random number generation algorithm, 1024 bits of entropy are taken from the CPU jitter entropy pool and compressed using the entropy compression function to obtain 256 bits of full entropy data. See also Figure 5 As shown in Figure (c), when random numbers generated by the CPU jitter entropy source and other entropy sources (such as interrupt entropy sources) are used together as the seed for the random number generation algorithm, if the interrupt entropy source and the CPU jitter entropy source are compressed to full entropy in equal proportions, then 512 bits of entropy are taken from the entropy pools of the CPU jitter entropy source and the interrupt entropy source, mixed to form 1024 bits of entropy, and compressed using an entropy compression function to obtain 256 bits of full entropy data. The entropy compression function can be SHA256. In both cases, the 256 bits of full entropy data are stored in the full entropy pool. The 256 bits (32 bytes) of full entropy data from the full entropy pool are used as the seed for the random number generation algorithm, which is then called to generate new random numbers.
[0092] The methods of the embodiments of this application have been described above; the apparatus of the embodiments of this application will be described below. It should be understood that the apparatus described below has any of the functions of the computing device in the above methods. (The above is in conjunction with...) Figures 2 to 5 The random number generation method provided according to the embodiments of this application is described in detail. Based on the same inventive concept, the following will be combined with Figure 6 This application describes a random number generation apparatus according to embodiments thereof. It should be understood that the technical features described in the method embodiments are also applicable to the following apparatus embodiments.
[0093] See Figure 6 This application provides a random number generation device, which includes a receiving module 601, a reading / writing module 602, and a generation module 603.
[0094] The receiving module 601 is used to receive a random number generation instruction, which instructs the generation of random numbers.
[0095] The read / write module 602 is used to execute multiple rounds of read / write events in response to random number generation instructions. The read / write events include a first read / write event and a second read / write event. The first read / write event is a read / write event for the first-level cache, and the second read / write event is a read / write event for the storage medium other than the first-level cache.
[0096] The generation module 603 is used to generate random numbers based on the time consumed by multiple rounds of read and write events.
[0097] In some embodiments, the storage medium other than the first-level cache is a second-level cache or memory.
[0098] In some embodiments, the read / write module 602 includes:
[0099] The determining unit is used to determine the read / write position of the i-th read / write event based on the system time corresponding to the n-th read / write event when executing the i-th read / write event in the n-th round of read / write events;
[0100] The read / write unit is used to execute the i-th read / write event based on the read / write position, where n is a positive integer greater than or equal to 1 and i is a positive integer greater than or equal to 1.
[0101] In some embodiments, the read / write module 602 includes:
[0102] The determining unit is used to determine the read / write position and write content of any read / write event in the nth round of read / write events, based on the system time corresponding to the nth round of read / write events.
[0103] The read / write unit is used to execute read / write events based on the read / write position and the content to be written, where n is a positive integer greater than or equal to 1.
[0104] In some embodiments, the determining unit is configured to determine the read / write position of the i-th read / write event based on the system time corresponding to the n-th round of read / write event and the read / write value of the (i-1)-th read / write event when i is greater than or equal to 2.
[0105] In some embodiments, the generation module 603 is configured to, if the generated random number fails the entropy quality detection, adjust at least one of the entropy taking position and the number of read / write operations, wherein the number of read / write operations is the number of read / write events that occur in each round of read / write events; and regenerate the random number based on the adjusted entropy taking position and the number of read / write operations.
[0106] In some embodiments, the generation module 603 is configured to perform any of the following: increase the number of read / write operations; move the entropy take position backward; move the entropy take position backward and reset the number of read / write operations to the initial number.
[0107] It should be understood that the random number generation device corresponds to the computing device in the above method embodiments. The modules in the device and the other operations and / or functions described above are for implementing various steps and methods carried out by the computing device in the method embodiments. For specific details, please refer to the above method embodiments. For the sake of brevity, they will not be repeated here.
[0108] Based on the above-mentioned random number generation device, an exemplary system architecture is given below. Figure 7 This is a schematic diagram of a system architecture provided in an embodiment of this application, used to implement the random number generation method provided in this embodiment. Figure 7 As shown, the system includes multiple functional modules such as a first random number generation module 701, a second random number generation module 702, a CPU 703, other hardware 704, an entropy source hybrid compression module 705, a new random number generation module 706, and a cryptographic algorithm module 707.
[0109] The first random number generation module (701) generates random numbers based on the CPU jitter entropy source and relies on the CPU (703) to generate output. The second random number generation module generates random numbers based on entropy sources other than the CPU jitter entropy source. These entropy sources include hardware interrupt entropy sources, software interrupt entropy sources, and network traffic entropy sources. Specifically, a hardware interrupt entropy source generates output based on interrupts triggered by hardware devices (such as keyboards and mice), a software interrupt entropy source generates output based on interrupts triggered by specific instructions or exceptions in an application, and a network traffic entropy source generates output based on network traffic timestamps, packet sizes, and network latency. The CPU (703) is the main processor in the computing device, and the other hardware (704) refers to all hardware in the computing device other than the main processor.
[0110] The CPU jitter entropy source can provide a random number seed for a random number generation algorithm independently, or it can provide a random number seed in conjunction with other entropy sources. When using the CPU jitter entropy source independently, the entropy source mixing and compression module 705 is used to compress the random numbers generated by that source. When using the CPU jitter entropy source in combination with other entropy sources, the entropy source mixing and compression module 705 is used to mix and compress the random numbers generated by these sources. This facilitates the comprehensive application of different entropy sources, thereby providing a high-quality random number seed. The new random number generation module 706 is used to generate new random numbers based on the random number seed provided by the entropy source, using a random number generation algorithm. The cryptographic algorithm 707 is used to use the new random numbers as keys or salts for encryption and decryption services, or for data security scenarios such as digital signatures and message authentication based on the new random numbers.
[0111] It should be noted that the first random number generation module 701 and CPU 703 are core modules, while other functional modules are optional.
[0112] The first random number generation module 701 includes multiple functional modules such as a two-dimensional row and column read / write module 7011, an adaptive digitization processing module 7012, an entropy acquisition module 7013, and an entropy detection module 7014. The two-dimensional row and column read / write module 7011 is used to respond to random number generation instructions, execute multiple rounds of read / write events, and obtain the time consumed by these events. The adaptive digitization processing module 7012 is used to generate random numbers based on the time consumed by the multiple rounds of read / write events. The adaptive digitization processing module 7012 is also used to adaptively adjust at least one of the entropy acquisition position and the number of read / write operations. The entropy acquisition module 7013 is used to count whether the entropy extracted from the time consumed by the multiple rounds of read / write events has accumulated to a preset amount. The entropy detection module 7014 is used to perform entropy quality detection on random numbers containing a preset amount of entropy. If the entropy quality detection passes, the random numbers can be provided for external use; if the entropy quality detection fails, the adaptive digitization processing module 7012 adaptively adjusts at least one of the entropy acquisition position and the number of read / write operations to regenerate random numbers.
[0113] In some embodiments, the adjustment strategy of the adaptive digitization processing module 7012 is any one of the following: increasing the number of read / write operations; moving the entropy taking position backward; moving the entropy taking position backward and resetting the number of read / write operations to the initial number.
[0114] In some embodiments, the two-dimensional row-column read / write module 7011 is used to determine the read / write position of the i-th read / write event based on the system time corresponding to the n-th read / write event when executing the i-th read / write event in the n-th round of read / write events; and execute the i-th read / write event based on the read / write position. Alternatively, when executing any read / write event in the n-th round of read / write events, the module determines the read / write position and the content to be written for the read / write event based on the system time corresponding to the n-th read / write event; and executes the read / write event based on the read / write position and the content to be written, where n is a positive integer greater than or equal to 1, and i is a positive integer greater than or equal to 1.
[0115] The above Figure 7 An exemplary partitioning of the functional modules used to implement the random number generation method is described. The CPU 703 and other hardware 704 in the above system architecture are further explained below. The CPU 703 and other hardware 704 reside in the same computing device. Figure 8 This is a schematic diagram of a computing device provided in an embodiment of this application. It should be understood that the computing device described below can implement any function of the random number generation method proposed in this application. See also... Figure 8 As shown, the computing device 800 includes a processor 801 and a memory 802.
[0116] Processor 801 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 801 may be implemented using at least one hardware form selected from digital signal processing (DSP), field-programmable gate array (FPGA), and programmable logic array (PLA). Processor 801 includes a main processor, which is a processor for processing data in the wake-up state, also known as a central processing unit (CPU); processor 801 may also include a coprocessor, which is a low-power processor for processing data in the standby state. In some embodiments, processor 801 may integrate a graphics processing unit (GPU), which is responsible for rendering and drawing the content required to be displayed on the screen. In some embodiments, processor 801 may also include an artificial intelligence (AI) processor, which is used to handle computational operations related to machine learning. Memory 802 may include one or more computer-readable storage media, which may be non-transitory. The memory 802 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash storage devices.
[0117] In this application, the processor 801 serves as the CPU, which is the hardware basis for CPU jitter events and also the basis for generating random numbers from the CPU jitter entropy source in this application. In some embodiments, the non-transitory computer-readable storage medium in the memory 802 stores at least one program segment, which is executed by the processor 801 to implement the random number generation method provided in the method embodiments of this application. Accordingly, different programs in the at least one program segment correspond to the different functional modules described above and respectively implement the functions indicated by the functional modules.
[0118] In this application embodiment, the computing device 800 can be configured as a terminal or a server, with the terminal or server acting as the execution entity to implement the technical solutions provided in this application embodiment. In some embodiments, the computing device 800 can be a portable mobile terminal, such as a smartphone, tablet computer, Moving Picture Experts Group Audio Layer III (MP3) player, Moving Picture Experts Group Audio Layer IV (MP4) player, laptop computer, or desktop computer. The computing device 800 may also be referred to as a user device, portable terminal, laptop terminal, desktop terminal, or other names.
[0119] In an exemplary embodiment, a computer-readable storage medium is also provided, such as a memory including program code that can be executed by a processor in a random number generation apparatus to perform the random number generation method in the above embodiments. For example, the computer-readable storage medium is a non-transitory computer-readable storage medium, such as a read-only memory (ROM), random access memory (RAM), compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, and optical data storage device.
[0120] This application also provides a computer program product or computer program, which includes program code. The computer instructions are stored in a computer-readable storage medium. A processor in a computing device reads the program code from the computer-readable storage medium and executes the program code, causing the computing device to perform the above-described random number generation method.
[0121] In addition, embodiments of this application also provide an apparatus, which may specifically be a chip, component or module. The apparatus may include a connected processor and a memory. The memory is used to store computer execution instructions. When the apparatus is running, the processor can execute the computer execution instructions stored in the memory to cause the chip to execute the random number generation method in the above-described method embodiments.
[0122] In this embodiment, the apparatus, device, computer-readable storage medium, computer program product or chip are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding methods provided above, and will not be repeated here.
[0123] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the random number generation method embodiments provided above belong to the same concept, and their specific implementation processes are detailed in the method embodiments, and will not be repeated here.
[0124] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0125] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0126] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0127] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially, or the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.
[0128] In the description of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B. The "and / or" in this document is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone. Furthermore, "at least one" means one or more, and "multiple" means two or more. The terms "first," "second," etc., do not limit the quantity or order of execution, and "first," "second," etc., do not necessarily imply differences.
[0129] In this application, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or illustration. Any embodiment or design described as "exemplary" or "for example" in this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the terms "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0130] It should be noted that all information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.), and signals involved in this application have been authorized by the user or fully authorized by all parties, and the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, the sensitive words involved in this application were obtained with full authorization.
[0131] All of the above-mentioned optional technical solutions can be combined in any way to form optional embodiments of this disclosure, and will not be described in detail here.
[0132] The above description is merely an optional embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for generating random numbers, characterized in that, The method includes: Receive a random number generation instruction, the random number generation instruction instructing the generation of random numbers; In response to the random number generation instruction, multiple rounds of read and write events are executed. The read and write events include a first read and write event and a second read and write event. The first read and write event is a read and write event for the first-level cache, and the second read and write event is a read and write event for the storage medium other than the first-level cache. Random numbers are generated based on the time consumed by the multiple rounds of read and write events.
2. The method according to claim 1, characterized in that, The storage medium other than the first-level cache is the second-level cache or memory.
3. The method according to claim 1, characterized in that, The execution of multiple rounds of read / write events includes: When executing the i-th read / write event in the n-th round of read / write events, the read / write position of the i-th read / write event is determined based on the system time corresponding to the n-th round of read / write events. Based on the read / write position, the i-th read / write event is executed, where n is a positive integer greater than or equal to 1, and i is a positive integer greater than or equal to 1.
4. The method according to claim 1, characterized in that, The execution of multiple rounds of read / write events includes: When executing any read / write event in the nth round of read / write events, the read / write position and the content to be written are determined based on the system time corresponding to the nth round of read / write events. The read / write event is executed based on the read / write position and the content to be written, where n is a positive integer greater than or equal to 1.
5. The method according to claim 3 or 4, characterized in that, Determining the read / write position of the read / write event based on the system time corresponding to the nth round of read / write events includes: When i is greater than or equal to 2, the read / write position of the i-th read / write event is determined based on the system time corresponding to the n-th read / write event and the read / write value of the (i-1)-th read / write event.
6. The method according to claim 1, characterized in that, The process of generating random numbers based on the time consumed by the multiple rounds of read / write events includes: If the generated random number fails the entropy quality test, adjust at least one of the entropy taking position and the number of read / write operations, where the number of read / write operations is the number of read / write events that occur in each round of read / write events; Based on at least one of the adjusted entropy position and read / write count, a new random number is generated.
7. The method according to claim 6, characterized in that, The adjustment of at least one of the entropy taking position and the number of read / write operations includes any one of the following: Increase the number of read / write operations; Move the entropy taking position backward; The entropy taking position is moved backward, and the read / write count is reset to the initial count.
8. A random number generation device, characterized in that, The device includes: A receiving module is configured to receive a random number generation instruction, wherein the random number generation instruction instructs the generation of random numbers; The read / write module is used to execute multiple rounds of read / write events in response to the random number generation instruction. The read / write events include a first read / write event and a second read / write event. The first read / write event is a read / write event for the first-level cache, and the second read / write event is a read / write event for the storage medium other than the first-level cache. The generation module is used to generate random numbers based on the time consumed by the multiple rounds of read and write events.
9. A computing device, characterized in that, The computing device includes a processor and a memory, the processor being configured to execute at least one piece of program code stored in the memory to enable the computing device to perform the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store at least one piece of program code, which, when executed by a computing device, causes the computing device to perform the method as described in any one of claims 1 to 7.
11. A computer program product, characterized in that, When the computer program product is run on a computing device, the computing device performs the method as described in any one of claims 1 to 7.