Random number generation method and device, equipment and storage medium

By using the system's built-in counter as the initial random seed, combined with linear congruence generator and linear combination technology, the problem of high probability of random number reproduction and slow generation in the pseudo-random number generator is solved, and a higher random number generation is achieved.

CN119987717APending Publication Date: 2025-05-13NANJING JINXIN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411878615.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-19
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

In the prior art, the pseudo-random number generator relies on initialized random seeds, resulting in the generated random numbers having a reproduction probability and the generation speed is slow.

Method used

By reading the built-in counter count value of the system as the initial random seed, a random system is generated using a linear congruent generator, and the two random systems are linearly combined to generate the final random number.

Benefits of technology

The randomness of the initial value and the randomness of the system are increased, the probability of reproducing the random number is reduced, and the speed of generation of random numbers is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119987717A_ABST
    Figure CN119987717A_ABST
Patent Text Reader

Abstract

The invention discloses a random number generation method and device, equipment and a storage medium, and the method comprises the steps: respectively reading count values of a first built-in counter and a second built-in counter in unit time, and respectively taking the count values as a first initial random seed and a second initial random seed; respectively taking the first initial random seed and the second initial random seed as initial numbers, and carrying out operation to generate a first random system and a second random system; and linearly combining the first random system and the second random system to generate a final random number. According to the invention, the counter built in the system is used as an acquisition object of the initial value, and the changed ns level of the counter is matched with the sampling interval ms level, so that the acquisition has irregularity, the randomness of the initial value is increased, and meanwhile, the two linear congruence generators are combined, so that the randomness of the system is further increased.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a random number generation method, device, equipment and storage medium. Background Art

[0002] The collection of entropy source of true random number generator usually obtains initial random data from physical noise, and the final generated true random number has high quality, but the random number generation mechanism is usually based on digital logic hardware implementation, so the generation speed is slow. Pseudo-random number generator is implemented by relying on seeds and specific random number generation algorithms. The quality of the generated random number is heavily dependent on the generation of seeds and the quality of the algorithm, but the generation of pseudo-random numbers also has the advantage of faster generation speed.

[0003] Currently, pseudo-random numbers calculated based on software usually need to be generated based on an initialized random seed. The random seed seems random but has a certain internal generation pattern, which makes the final generated random number have a certain probability of recurrence. Summary of the invention

[0004] The technical problem to be solved by the present invention is to overcome the shortcomings of the prior art and provide a method, device, equipment and storage medium for generating random numbers.

[0005] In order to solve the above technical problems, the technical solution of the present invention is as follows: A method for generating a random number, comprising: Reading the count values ​​of the first built-in counter and the second built-in counter in a unit time respectively, and using them as the first initial random seed and the second initial random seed respectively; Using the first initial random seed and the second initial random seed as initial numbers respectively, performing calculations to generate a first random system and a second random system; The first random system and the second random system are linearly combined to generate a final random number.

[0006] As a preferred solution of the random number generation method of the present invention, wherein: the first initial random seed and the second initial random seed are used as initial numbers to perform calculations to generate the first random system and the second random system, respectively, including: Using the first initial random seed obtained in each unit time as the initial number, generating a first random system through a linear congruential generator; The second initial random seed obtained in each unit time is used as the initial number, and the second random system is generated by a linear congruential generator.

[0007] As a preferred solution of the random number generation method of the present invention, the linear combination of the first random system and the second random system to generate the final random number includes: The first random system is linearly added to the second random system and the modulus is taken, and the value of the modulus length is used as the value of the random number range.

[0008] As a preferred solution of the random number generation method of the present invention, wherein: the unit time is 2ms.

[0009] As a preferred solution of the random number generation method of the present invention, the frequency of change of data in the first built-in counter and the second built-in counter is at nanosecond level.

[0010] The present invention also provides a random number generation device, comprising: An acquisition module, used to read the count values ​​of the first built-in counter and the second built-in counter respectively within a unit time, and use them as the first initial random seed and the second initial random seed respectively; A calculation module, used for taking the first initial random seed and the second initial random seed as initial numbers, performing calculations to generate a first random system and a second random system; The generating module is used for linearly combining the first random system and the second random system to generate a final random number.

[0011] As a preferred solution of the random number generating device of the present invention, wherein: the calculation module includes a first calculation module and a second calculation module; The first calculation module is used to use the first initial random seed obtained in each unit time as an initial number to generate a first random system through a linear congruential generator; The second calculation module is used to use the second initial random seed obtained in each unit time as the initial number to generate a second random system through a linear congruential generator.

[0012] The present invention also provides a computer device, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in any of the above-mentioned random number generation methods when executing the program.

[0013] The present invention also provides a computer-readable storage medium having a computer program stored thereon, characterized in that when the program is executed by a processor, the method described in any of the above-mentioned random number generation methods is implemented.

[0014] The beneficial effects of the present invention are: The present invention utilizes the built-in counter of the system as the object for obtaining the initial value, and the ns level of the counter change is matched with the ms level of the sampling interval, so that the collection itself has irregularity, which increases the randomness of the initial value. At the same time, two linear congruential generators are combined to further increase the randomness of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0016] Figure 1 A schematic diagram of a flow chart of a random number generation method provided by the present invention. ; Figure 2 Schematic diagram of the random carrier frequency generation process in Example 1; Figure 3 This is a schematic diagram of the random number effect generated in Example 1; Figure 4 A schematic diagram of a random number generating device provided by the present invention; Figure 5 A schematic diagram of a computer device provided by the present invention. DETAILED DESCRIPTION

[0017] In order to make the content of the present invention more clearly understood, the present invention is further described in detail below according to specific implementation modes and in combination with the accompanying drawings.

[0018] Figure 1 The following is a flow chart of the random number generation method provided in this application. The method specifically includes the following steps: Step S101: reading the count values ​​of the first built-in counter and the second built-in counter in a unit time respectively, and using them as the first initial random seed and the second initial random seed respectively.

[0019] Specifically, the count value of the first built-in counter is read in a unit time as the first initial random seed. The count value of the second built-in counter is read in a unit time as the second initial random seed.

[0020] In this embodiment, the unit time is 2 ms, that is, the current count values ​​of the first built-in counter and the second built-in counter are read every 2 ms and used as the first initial random seed and the second initial random seed respectively.

[0021] It should be noted that the frequency of change of the data in the first built-in counter and the second built-in counter is at nanosecond level.

[0022] Step S102: using the first initial random seed and the second initial random seed as initial numbers respectively, performing calculations to generate a first random system and a second random system.

[0023] Specifically, the first initial random seed obtained in each unit time is used as the initial number to generate the first random system through a linear congruential generator; the second initial random seed obtained in each unit time is used as the initial number to generate the second random system through a linear congruential generator.

[0024] Step S103: linearly combine the first random system and the second random system to generate a final random number.

[0025] Specifically, the results generated by two linear congruential generators are linearly added and the modulus is taken. The value of the modulus length is the value of the random number range.

[0026] It should be noted that the first random system and the second random system for linear combination are generated by initial random seeds obtained within the same unit time.

[0027] Therefore, the above technical solution uses the built-in counter of the system as the object for obtaining the initial value. The ns level of the counter change is combined with the ms level of the sampling interval, which makes the collection itself irregular, increasing the randomness of the initial value. At the same time, the two linear congruential generators are combined to further increase the randomness of the system.

[0028] The following is further described by means of specific examples.

[0029] Embodiment 1: Assign the random number generated by the above technical solution to the control carrier frequency of the motor control algorithm to generate a random carrier frequency for EMC and noise elimination. The random carrier frequency generation process is shown in Figure 2 The random number effect is shown in Figure 3 .

[0030] Figure 4 A schematic diagram of a random number generation device provided in the present application. The device includes: an acquisition module, a calculation module and a generation module.

[0031] Specifically, the acquisition module is used to read the count values ​​of the first built-in counter and the second built-in counter respectively within a unit time, and use them as the first initial random seed and the second initial random seed respectively.

[0032] The calculation module is used to use the first initial random seed and the second initial random seed as initial numbers, perform calculations, and generate a first random system and a second random system.

[0033] Specifically, the calculation module includes a first calculation module and a second calculation module. The first calculation module is used to use the first initial random seed obtained in each unit time as the initial number to generate a first random system through a linear congruential generator. The second calculation module is used to use the second initial random seed obtained in each unit time as the initial number to generate a second random system through a linear congruential generator. The generation module is used to linearly combine the first random system and the second random system to generate a final random number.

[0034] See also Figure 5 This embodiment also provides a computer device, and the components of the computer device may include but are not limited to: one or more processors or processing units, a system memory, and a bus connecting different system components (including the system memory and the processing unit).

[0035] The term "bus" refers to one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.

[0036] The computer system / server typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer system / server, including volatile and non-volatile media, removable and non-removable media.

[0037] The system memory may include computer system readable media in the form of volatile memory, such as random access memory (RAM) and / or cache memory. The computer device may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system may be used to read and write non-removable, non-volatile magnetic media. A disk drive for reading and writing removable non-volatile disks (such as "floppy disks") and an optical disk drive for reading and writing removable non-volatile optical disks (such as CD-ROMs, DVD-ROMs or other optical media) may be provided. In these cases, each drive may be connected to the bus via one or more data medium interfaces. The memory may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.

[0038] A program / utility having a set (at least one) of program modules may be stored, for example, in a memory, such program modules including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules generally perform the functions and / or methods of the embodiments described herein.

[0039] The computer device may also communicate with one or more external devices such as a keyboard, a pointing device, a display, etc. Such communication may be performed through an input / output (I / O) interface. Furthermore, the computer device may also communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN) and / or a public network, such as the Internet) through a network adapter.

[0040] The processing unit executes the functions and / or methods described in the embodiments of the present invention by running the programs stored in the system memory.

[0041] The above-mentioned computer program can be set in a computer storage medium, that is, the computer storage medium is encoded with a computer program, and when the program is executed by one or more computers, it enables one or more computers to execute the method flow and / or device operation shown in the above-mentioned embodiments of the present invention.

[0042] With the development of time and technology, the meaning of medium is becoming more and more extensive, and the propagation path of computer programs is no longer limited to tangible media, but can also be downloaded directly from the network, etc. Any combination of one or more computer-readable media can be used. Computer-readable media can be computer-readable signal media or computer-readable storage media. Computer-readable storage media can be, for example, - but not limited to - electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or devices, or any combination of the above. More specific examples of computer-readable storage media (non-exhaustive list) include: electrical connections with one or more wires, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this document, computer-readable storage media can be any tangible medium containing or storing programs, which can be used by or in combination with instruction execution systems, devices or devices.

[0043] Computer-readable signal media may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0044] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0045] Computer program code for performing the operations of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0046] In addition to the above embodiments, the present invention may also have other implementation modes; any technical solutions formed by equivalent replacement or equivalent transformation shall fall within the protection scope required by the present invention.

Claims

1. A method for generating a random number, characterized in that: include: Reading the count values ​​of the first built-in counter and the second built-in counter in a unit time respectively, and using them as the first initial random seed and the second initial random seed respectively; The first initial random seed and the second initial random seed are respectively used as initial numbers to perform calculations to generate a first random system and a second random system; The first random system and the second random system are linearly combined to generate a final random number.

2. The method for generating random numbers according to claim 1, wherein: The method of using the first initial random seed and the second initial random seed as initial numbers to generate the first random system and the second random system comprises: Using the first initial random seed obtained in each unit time as the initial number, generating a first random system through a linear congruential generator; The second initial random seed obtained in each unit time is used as the initial number, and the second random system is generated by a linear congruential generator.

3. The method for generating random numbers according to claim 1, wherein: The linear combination of the first random system and the second random system to generate a final random number comprises: The first random system is linearly added to the second random system and the modulus is taken, and the value of the modulus length is used as the value of the random number range.

4. The method for generating random numbers according to claim 1, wherein: The unit time is 2 ms.

5. The method for generating random numbers according to claim 1, wherein: The frequency of data changes in the first built-in counter and the second built-in counter is at the nanosecond level.

6. A random number generating device, characterized in that: include: An acquisition module, used to read the count values ​​of the first built-in counter and the second built-in counter respectively within a unit time, and use them as the first initial random seed and the second initial random seed respectively; A calculation module, used for taking the first initial random seed and the second initial random seed as initial numbers, performing calculations to generate a first random system and a second random system; The generating module is used for linearly combining the first random system and the second random system to generate a final random number.

7. The random number generating device according to claim 6, characterized in that: The calculation module includes a first calculation module and a second calculation module; The first calculation module is used to use the first initial random seed obtained in each unit time as an initial number to generate a first random system through a linear congruential generator; The second calculation module is used to use the second initial random seed obtained in each unit time as the initial number to generate a second random system through a linear congruential generator.

8. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 5 is implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.