A method, computing device, and storage medium for generating random numbers

By generating random numbers using XOR operations on system time and process information during process scheduling in the Linux system, the problem of insufficient random number storage pool is solved, enabling random number generation even without hardware chips, thus ensuring system stability and business continuity.

CN122240065APending Publication Date: 2026-06-19NEW H3C TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
NEW H3C TECH CO LTD
Filing Date
2026-04-27
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

Insufficient random number storage pool in Linux systems leads to problems with encryption, security, and network service interruptions. Existing hardware interrupts rely on external hardware triggers for random number generation, which have limited speed, resulting in insufficient random number generation when external hardware triggers are infrequent.

Method used

By performing an XOR operation on the system time of the process scheduling switch and the process information before and after the process scheduling switch to generate a random number, including the process ID and memory usage, the periodic scheduler or the main scheduler calls the CFS or EEVDF scheduler to determine the process switch and obtain relevant information.

Benefits of technology

By generating more random numbers without the need for a random number hardware chip, the problem of insufficient random numbers generated by hardware interrupts is solved, ensuring system stability and business continuity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122240065A_ABST
    Figure CN122240065A_ABST
Patent Text Reader

Abstract

This specification provides a method, computing device, and storage medium for generating random numbers. The method includes: when a process scheduling switch is detected, obtaining the system time of the process scheduling switch, process information before the process scheduling switch, and process information after the process scheduling switch; and using the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch to perform an XOR operation to generate random numbers. This method enables software-based random number generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of operating system technology, and in particular to a method, computing device, and storage medium for generating random numbers. Background Technology

[0002] Linux Operating System: Linux is an open-source, Unix-like operating system originally developed by Linus Torvalds in 1991. It is renowned for its stability, high security, and flexibility, and is widely used on various platforms including servers, desktop computers, embedded systems, and mobile devices.

[0003] Linux Process Scheduler: The Linux process scheduler is a core component of the operating system kernel, responsible for managing the allocation of CPU resources and determining which process (or thread) acquires CPU execution rights and when. Its core goal is to schedule tasks efficiently and fairly, while meeting the performance requirements of different scenarios (such as low latency, high throughput, or real-time performance).

[0004] Master Scheduler: In many parts of the kernel, when the CPU needs to be actively allocated to another process that is not currently active, the scheduler function (schedule) is called directly. For example, when a process acquires a lock and needs to actively trigger scheduling, the master scheduler function is called.

[0005] Periodic Scheduler: The periodic scheduler is implemented in the function (schedule_tick). If the system is active, the kernel will automatically call this function at a frequency of HZ. HZ is typically set to 1000, in which case schedule_tick is called once every 1 millisecond.

[0006] like Figure 1 As shown, Linux is an open-source, Unix-like operating system widely used on various platforms such as servers, desktop computers, embedded systems, and mobile devices.

[0007] Linux ordinary processes (non-real-time processes) are typically scheduled and run using the CFS scheduler or the EEVDF scheduler, while Linux real-time processes are scheduled and run using the real-time scheduler, and Linux idle threads are scheduled and run using the idle scheduler.

[0008] Master Scheduler: In many parts of the kernel, when the CPU needs to be actively allocated to another process that is not currently active, the scheduler function (schedule) is called directly. For example, when a process acquires a lock and needs to actively trigger scheduling, the master scheduler function is called.

[0009] Periodic Scheduler: The periodic scheduler is implemented in the function (schedule_tick). If the system is active, the kernel will automatically call this function at a frequency of HZ. HZ is typically set to 1000, in which case schedule_tick is called once every 1 millisecond.

[0010] When the master scheduler or periodic scheduler triggers scheduling, they will select one of the following schedulers according to the strategy: CFS scheduler, EEVDF scheduler, real-time scheduler, and idle scheduler. Then, through the scheduling algorithm of these four schedulers, the process under their management is selected for scheduling and execution.

[0011] The CFS scheduler and the EEVDF scheduler are used for scheduling ordinary processes. Generally, one of them is chosen; in older kernel versions, the CFS scheduler is usually used by default, while in newer kernel versions, the EEVDF scheduler is used by default. Both use virtual runtime for counting, with the unit of virtual runtime being nanoseconds.

[0012] Random numbers are a series of values ​​that do not exhibit a clear pattern or predictability within a specific range. In computer science, mathematics, and statistics, random numbers are widely used to simulate and analyze random events.

[0013] In Linux systems, random numbers are used in encryption, security, and network services. A random number pool exists; each time a random number is used, the number of random numbers in the pool decreases by one; conversely, each time a random number is generated, the number of random numbers in the pool increases by one. However, when a large number of random numbers are consumed, the pool may run out of random numbers, causing services using random numbers to be interrupted, resulting in disruptions to encryption, security, and network services. Summary of the Invention

[0014] To overcome the problems existing in related technologies, this specification provides a method, computing device, and storage medium for generating random numbers.

[0015] According to a first aspect of the embodiments of this specification, a method for generating random numbers is provided, the method being applied to a Linux system, the method comprising: When a process scheduling switch is detected, obtain the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch. Random numbers are generated by performing XOR operations on the system time of process scheduling switching, process information before process scheduling switching, and process information after process scheduling switching. The process information includes one or both of the process ID and memory usage.

[0016] The step of obtaining the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch when a process scheduling switch is detected includes: When the CFS scheduler or EEVDF scheduler is called through the periodic scheduler or the master scheduler, the scheduler algorithm is used to determine whether a process scheduling switch has occurred. If a process scheduling switch is detected, the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch are obtained.

[0017] The methods for obtaining process information before process scheduling switching include: When a process scheduling switch is detected, the scheduler is triggered to obtain process information before the process scheduling switch. The process information obtained before the process scheduling switch is recorded in memory.

[0018] The process scheduling switching system time acquisition includes: Record the first system time during process scheduling and switching; Remove the millisecond-level integer data of the first system time and retain the nanosecond-level integer data; Nanosecond-level integer data is used as the system time for process scheduling and switching.

[0019] The step of generating random numbers by performing an XOR combination operation on the system time of process scheduling switch, process information before process scheduling switch, and process information after process scheduling switch includes: Random number = (system time of process scheduling switch) XOR (process information before process scheduling switch) XOR (process information after process scheduling switch).

[0020] The methods described in the above embodiments, and the methods for generating random numbers provided in this disclosure, can solve the technical problem of insufficient random numbers in the system.

[0021] According to a second aspect of the embodiments of this specification, a computing device is provided, the computing device running a Linux system, the computing device comprising: The acquisition module is used to identify when a process scheduling switch occurs and to acquire the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch. The processing module is used to generate random numbers by performing XOR combination operations on the system time of process scheduling switch, process information before process scheduling switch and process information after process scheduling switch; The process information includes one or both of the process ID and memory usage.

[0022] Specifically, the acquisition module is used to determine whether a process scheduling switch has occurred when the CFS scheduler or EEVDF scheduler is called by the periodic scheduler or the main scheduler. If a process scheduling switch is detected, the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch are obtained.

[0023] Specifically, the acquisition module is used to trigger the scheduler to acquire process information before the process scheduling switch when a process scheduling switch is detected. The process information obtained before the process scheduling switch is recorded in memory.

[0024] Specifically, the acquisition module is used to record the first system time during process scheduling and switching; Remove the millisecond-level integer data of the first system time and retain the nanosecond-level integer data; Nanosecond-level integer data is used as the system time for process scheduling and switching.

[0025] The processing module obtains random numbers using the following formula; Random number = (system time of process scheduling switch) XOR (process information before process scheduling switch) XOR (process information after process scheduling switch).

[0026] According to a third aspect of the embodiments of this specification, a computing device is provided, the computing device comprising: a memory, a processor, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements any of the above-described method embodiments.

[0027] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided, on which a program is stored, which, when executed by a processor, implements any of the above-described method embodiments.

[0028] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this specification. Attached Figure Description

[0029] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this specification and, together with the description, serve to explain the principles of this specification.

[0030] Figure 1 This is a schematic diagram of a Linux scheduler and process scheduling architecture illustrated in this specification according to an exemplary embodiment.

[0031] Figure 2This is a schematic flowchart illustrating a method for generating random numbers according to an exemplary embodiment. Detailed Implementation

[0032] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this specification. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this specification as detailed in the appended claims.

[0033] The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of this specification. The singular forms “a,” “the,” and “the” as used in this specification and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.

[0034] It should be understood that although the terms first, second, third, etc., may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this specification, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."

[0035] Currently, Linux systems generate random numbers using a random number hardware chip. However, this requires an additional random number hardware chip, increasing the hardware cost of the product.

[0036] While Linux systems can generate random numbers via hardware interrupts—including those from the mouse, keyboard, and network chips—the arrival time of the interrupt and the data read are used to calculate and generate random numbers. For example, with the keyboard, when we press keys, the computer records the current system time and the data entered, and then calculates and generates random numbers.

[0037] However, Linux hardware interrupts rely on external hardware triggers to generate random numbers, such as mouse or keyboard clicks, or network chip sending and receiving data packets. This results in a high degree of randomness; if no hardware interrupt occurs (e.g., no one clicks the mouse or keyboard), random number generation will stop. Furthermore, the speed at which hardware interrupts generate random numbers is relatively limited, especially when external hardware triggers are infrequent. Excessive use of random numbers can lead to the Linux system running out of random numbers.

[0038] To address the aforementioned technical problems, this disclosure provides a method for generating random numbers, which is applied to a Linux system, such as... Figure 2 As shown, the method includes: When S201 detects a process scheduling switch, it obtains the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch. S202 uses the system time of process scheduling switch, process information before process scheduling switch and process information after process scheduling switch to perform data XOR combination operation to generate random numbers; The process information includes one or both of the process ID and memory usage.

[0039] In this embodiment, the periodic scheduler is a clock interrupt-driven scheduling component in the Linux kernel. It is triggered to execute at fixed time intervals (usually 1 millisecond or 10 milliseconds) and is responsible for monitoring the system's operating status and preparing for scheduling decisions.

[0040] The master scheduler is the core component in the Linux kernel responsible for actually switching between processes. It selects the next process to run based on the scheduling policy and performs the context switch.

[0041] In this embodiment, we mainly consider the situation where process scheduling switching occurs when the periodic scheduler or the master scheduler selects the CFS scheduler or the EEVDF scheduler.

[0042] The CFS (Completely Fair Scheduler) scheduler is the default process scheduler in the Linux kernel, used to manage CPU time allocation for ordinary (non-real-time) processes. Its core goal is to fairly allocate CPU resources to all runnable processes while ensuring good interactivity and system throughput.

[0043] EEVDF (Earliest Eligible Virtual Deadline First) is a novel process scheduling algorithm introduced in the Linux kernel, designed to improve the performance of traditional CFS (Completely FairScheduler) in high-load or latency-sensitive scenarios. EEVDF combines fairness and low latency design principles, dynamically calculating the virtual deadlines of tasks to determine the scheduling order, thereby optimizing the responsiveness of interactive tasks and real-time applications.

[0044] The CFS scheduler and EEVDF scheduler are used for scheduling ordinary processes. The periodic scheduler or the main scheduler will choose one of the two schedulers based on the device's requirements. In older kernel versions, the CFS scheduler is generally used by default; in newer kernel versions, the EEVDF scheduler is used by default. Both schedulers use virtual runtime for counting, with the unit of virtual runtime being nanoseconds.

[0045] In this embodiment, the CFS scheduler or EEVDF scheduler can determine whether a process scheduling switch has occurred through a scheduler algorithm. For example, by maintaining a sophisticated accounting system and triggering mechanism, it can decide to switch at the appropriate time. The entire identification process can be divided into three levels: accounting, triggering, and decision-making.

[0046] For example, CFS maintains a key variable for each process: virtual runtime. Each CPU has a CFS run queue where all runnable processes are sorted by their vruntime in ascending order and stored in a red-black tree. The leftmost node of the tree is the process with the smallest vruntime. The process that needs to be scheduled is determined by periodic checks and event-driven checks, and the process scheduling switch is identified by determining the scheduling point and performing the switch.

[0047] In this embodiment, when a process scheduling switch is detected, the scheduler is triggered to obtain process information before the process scheduling switch, such as obtaining the process ID and / or memory usage before the process scheduling switch, and recording the obtained process ID and / or memory usage before the process scheduling switch in memory for storage.

[0048] In this embodiment, when the scheduler performs process scheduling switch, it records the first system time of the process scheduling switch. Since the first system time is an integer in milliseconds that increments by 1, it is not very random. Therefore, the first system time is removed in milliseconds and only the nanosecond integer data is retained. That is, the system time in step S201 = first system time (in nanoseconds) - the first system time in milliseconds (in nanoseconds).

[0049] For example, if the obtained system time is 10.123456 milliseconds, then the processed system time is 123456 nanoseconds. Therefore, the processed system time ranges from 0 nanoseconds to 99999 nanoseconds, which is represented in hexadecimal as 0x0 nanoseconds to 0x1869F.

[0050] In step S202, random numbers can be generated using the following formula: Random number = (system time of process scheduling switch) XOR (process information before process scheduling switch) XOR (process information after process scheduling switch).

[0051] The process information can be selected as either the process ID or the memory usage size, or both, depending on the requirements. For example, when the process information is the process ID and the memory usage size, Random number = (system time of process scheduling switch) XOR (process ID of the process before scheduling switch) XOR (memory usage of the process before scheduling switch) XOR (process ID of the process after scheduling switch) XOR (memory usage of the process after scheduling switch).

[0052] The lowest 32 bits of the final random number are taken, that is, the final random number = (the obtained random number) and (0xFFFF), and it is added to the system random number pool.

[0053] To illustrate the solution in this disclosure in detail, an embodiment of this disclosure also provides an example. For instance, when process scheduling switching is identified in step S201, the first system time of the process scheduling switch is obtained as 200.123456 milliseconds. The system time after removing the millisecond-level integer data and retaining the nanosecond-level integer data is 123456. The process ID of the process before the scheduling switch is 200, and the memory size is 96345KB. The process ID of the process after the scheduling switch is 600, and the memory size is 10123456KB.

[0054] Substituting the above data into the formula, we obtain: Random number = (123456)^(200)^(96345)^(600)^10123456 = 10149961. The final random number is obtained by taking the lower 32 bits, that is, the final random number = (the obtained random number) and (0xFFFF). It is added to the system random number pool, and the final random number = 10149961&0xFFFF = 0xe049.

[0055] The method provided by this disclosure can generate more random numbers through software functions in the absence of a random number hardware chip, thereby solving the technical problem of insufficient random number generation in time periods with few hardware interrupts (infrequent external hardware triggers).

[0056] Based on the above method embodiments, this disclosure also provides a computing device running a Linux system, the computing device comprising: The acquisition module is used to identify when a process scheduling switch occurs and to acquire the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch. The processing module is used to generate random numbers by performing XOR combination operations on the system time of process scheduling switch, process information before process scheduling switch and process information after process scheduling switch; The process information includes one or both of the process ID and memory usage.

[0057] Specifically, the acquisition module is used to determine whether a process scheduling switch has occurred when the CFS scheduler or EEVDF scheduler is called by the periodic scheduler or the main scheduler. If a process scheduling switch is detected, the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch are obtained.

[0058] Specifically, the acquisition module is used to trigger the scheduler to acquire process information before the process scheduling switch when a process scheduling switch is detected. The process information obtained before the process scheduling switch is recorded in memory.

[0059] Specifically, the acquisition module is used to record the first system time during process scheduling and switching; Remove the millisecond-level integer data of the first system time and retain the nanosecond-level integer data; Nanosecond-level integer data is used as the system time for process scheduling and switching.

[0060] The processing module obtains random numbers using the following formula; Random number = (system time of process scheduling switch) XOR (process information before process scheduling switch) XOR (process information after process scheduling switch).

[0061] Meanwhile, this disclosure also provides a computing device, which includes: a memory, a processor, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements any of the above-described method embodiments.

[0062] This disclosure also provides a computer-readable storage medium storing a program that, when executed by a processor, implements any of the above-described method embodiments.

[0063] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of the solution in this specification according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0064] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0065] Other embodiments of this specification will readily occur to those skilled in the art upon consideration of the specification and practice of the invention claimed herein. This specification is intended to cover any variations, uses, or adaptations that follow the general principles of this specification and include common knowledge or customary techniques in the art not claimed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this specification are indicated by the following claims.

[0066] It should be understood that this specification is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this specification is limited only by the appended claims.

[0067] The above description is merely a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of protection of this specification.

Claims

1. A method of generating a random number, characterized by, The method is applied to a Linux system, and the method includes: When a process scheduling switch is detected, obtain the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch; Random numbers are generated by performing XOR operations on the system time of process scheduling switching, process information before process scheduling switching, and process information after process scheduling switching. The process information includes one or both of the process ID and memory usage.

2. The method of claim 1, wherein, When a process scheduling switch is detected, the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch are obtained, including: When the CFS scheduler or EEVDF scheduler is called through the periodic scheduler or the master scheduler, the scheduler algorithm is used to determine whether a process scheduling switch has occurred. If a process scheduling switch is detected, the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch are obtained.

3. The method of claim 1, wherein, Methods for obtaining process information before a process scheduling switch include: When a process scheduling switch is detected, the scheduler is triggered to obtain process information before the process scheduling switch. The process information obtained before the process scheduling switch is recorded in memory.

4. The method of claim 1, wherein, The process scheduling switch system time acquisition includes: Record the first system time during process scheduling and switching; Remove the millisecond-level integer data of the first system time and retain the nanosecond-level integer data; Nanosecond-level integer data is used as the system time for process scheduling and switching.

5. The method according to claim 1, characterized in that, The step of generating random numbers by performing an XOR combination operation on the system time of process scheduling switch, process information before process scheduling switch, and process information after process scheduling switch includes: Random number = (system time of process scheduling switch) XOR (process information before process scheduling switch) XOR (process information after process scheduling switch).

6. A computing device, characterized in that, The computing device runs a Linux system, and the computing device includes: The acquisition module is used to identify when a process scheduling switch occurs and to acquire the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch. The processing module is used to generate random numbers by performing XOR combination operations on the system time of process scheduling switch, process information before process scheduling switch and process information after process scheduling switch; The process information includes one or both of the process ID and memory usage.

7. The computing device according to claim 6, characterized in that, The acquisition module is specifically used to determine whether a process scheduling switch has occurred when the CFS scheduler or EEVDF scheduler is called by the periodic scheduler or the main scheduler. If a process scheduling switch is detected, the system time of the process scheduling switch, the process information before the process scheduling switch, and the process information after the process scheduling switch are obtained.

8. The computing device according to claim 6, characterized in that, The acquisition module is specifically used to trigger the scheduler to acquire process information before the process scheduling switch when a process scheduling switch is detected. The process information obtained before the process scheduling switch is recorded in memory.

9. The computing device according to claim 6, characterized in that, The acquisition module is specifically used to record the first system time during process scheduling and switching; Remove the millisecond-level integer data of the first system time and retain the nanosecond-level integer data; Nanosecond-level integer data is used as the system time for process scheduling and switching.

10. The computing device according to claim 6, characterized in that, The processing module obtains random numbers using the following formula; Random number = (system time of process scheduling switch) XOR (process information before process scheduling switch) XOR (process information after process scheduling switch).

11. A computing device, characterized in that, The computing device includes: a memory, a processor, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements the method steps as described in any one of claims 1 to 5.

12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a program that, when executed by a processor, implements the method steps as described in any one of claims 1 to 5.