Random number generation method, device, storage medium and processor
By simplifying the random number generation method and calculating random numbers using the displacement of movable reference points, the problems of complex and costly random number generation in the prior art are solved, and fast and convenient random number generation is achieved.
Patent Information
- Application Number
- CN202111631070.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-28
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2041-12-28
AI Technical Summary
In the prior art, the random number generation method is complex and the physical conditions are harsh, which makes generation difficult and costly, making it difficult to effectively implement in software applications.
By determining the starting position of the movable reference point and randomly generating its movement direction and speed, recording the difference between the movement termination time and the starting time, and calculating the random number based on the displacement, simplifying the random number generation process.
It realizes the rapid and convenient generation of random numbers, reduces the generation cost, and solves the problems of harsh physical conditions and complex methods.
Smart Images

Figure CN114489568B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular to a method, device, storage medium and processor for generating random numbers. Background Art
[0002] When encrypting data, random numbers are often needed. In the related art, a true random number generator based on the Brownian motion of liquid molecules can generally generate random numbers. However, the physical conditions of this method are demanding. It is necessary to place a mixture of particles that perform Brownian motion in a high-pressure container, periodically shoot cross-sections, and perform multiple processing to obtain genetic random numbers. The cost of use is extremely high, and it is even more impractical in the software industry. That is, the method of generating random numbers in the related art has the technical problems of complex operation, high cost, extremely demanding physical adjustment, and difficulty in effective implementation in actual software applications.
[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0004] The embodiments of the present application provide a method, device, storage medium and processor for generating random numbers, so as to at least solve the technical problems that the random number generation method in the related art is complicated and the physical conditions are extremely harsh, which makes the random number generation difficult, technically difficult to implement and the generation cost is high.
[0005] According to one aspect of an embodiment of the present application, a method for generating a random number is provided, including: determining a starting position of a movable reference point; randomly generating a moving direction and a moving speed of the movable reference point, controlling the movable reference point to move from the starting position along the moving direction at the moving speed, and recording the starting moment of the movable reference point moving along the moving direction at the moving speed; stopping the movement of the movable reference point at any moment, determining a movement termination moment of the movable reference point, and determining a difference between the movement termination moment and the start moment; determining a displacement of the movable reference point according to the moving direction, the moving speed and the difference; determining a random number according to the displacement, wherein the random number can at least be used to encrypt data to be encrypted.
[0006] Optionally, before determining the random number according to the displacement, the method further includes: determining the starting position as the origin of the plane coordinate system; and determining the angle between the trajectory corresponding to the displacement and the horizontal axis of the plane coordinate system.
[0007] Optionally, determining a random number based on the displacement includes: obtaining an endpoint coordinate point of a movable reference point in a plane coordinate system based on the displacement and the angle, wherein the endpoint coordinate point includes: a group of ordered number pairs, wherein a group of ordered number pairs includes: a first element value along a horizontal axis and a second element value along a vertical axis of the plane coordinate system; obtaining a random number based on the first element value and the second element value.
[0008] Optionally, the endpoint coordinate point of the movable reference point in the plane coordinate system is obtained according to the displacement and the angle, including: determining the cosine value corresponding to the angle, and obtaining the first element value according to the product of the cosine value and the displacement; determining the sine value corresponding to the angle, and obtaining the second element value according to the product of the sine value and the displacement.
[0009] Optionally, obtaining a random number based on the first element value and the second element value includes: determining a first square value of the first element value; determining an absolute value of the second element value and a second square value of the second element value; and obtaining a random number based on at least the first element value, the first square value, the absolute value of the second element value and the second square value.
[0010] Optionally, after determining the absolute value of the second element value and the second square value of the second element value, it includes: randomly selecting a target symbol from a symbol list; obtaining a predetermined splicing rule, wherein the splicing rule is used to indicate the combination order of the first element value, the first square value, the absolute value of the second element value, the second square value and the target symbol.
[0011] Optionally, a random number is obtained based on at least the first element value, the first square value, the absolute value and the second square value, including: splicing the first element value, the first square value, the absolute value of the second element value, the second square value and the target symbol based on a combination order indicated by a predetermined splicing rule to obtain a random number.
[0012] According to another aspect of an embodiment of the present application, a random number generating device is also provided, including: a first determination module, used to determine the starting position of a movable reference point; a control module, used to randomly generate a moving direction and a moving speed of the movable reference point, control the movable reference point to move from the starting position along the moving direction at the moving speed, and record the starting moment when the movable reference point moves along the moving direction at the moving speed; a second determination module, used to stop the movement of the movable reference point at any moment, determine the movement end moment of the movable reference point, and determine the difference between the movement end moment and the start moment; a third determination module, used to determine the displacement of the movable reference point according to the moving direction, the moving speed and the difference; a fourth determination module, used to determine a random number according to the displacement, wherein the random number can at least be used to encrypt the encrypted data.
[0013] According to another aspect of an embodiment of the present application, a non-volatile storage medium is further provided, the non-volatile storage medium including a stored program, wherein when the program is running, the device where the non-volatile storage medium is located is controlled to execute any random number generation method.
[0014] According to another aspect of an embodiment of the present application, a processor is further provided, and the processor is used to run a program, wherein any random number generation method is executed when the program is running.
[0015] In the embodiment of the present application, a method of generating random numbers according to physical movement is adopted, by determining the starting position of the movable reference point;
[0016] The moving direction and moving speed of a movable reference point are randomly generated, the movable reference point is controlled to move from a starting position along the moving direction at the moving speed, and the starting moment of the movable reference point moving along the moving direction at the moving speed is recorded; the movement of the movable reference point is stopped at any moment, the movement end moment of the movable reference point is determined, and the difference between the movement end moment and the starting moment is determined; the displacement of the movable reference point is determined according to the moving direction, the moving speed and the difference; the random number is determined according to the displacement, so as to achieve the technical effect of quickly and conveniently generating random numbers and greatly saving the generation cost, thereby solving the technical problems that the random number generation method in the related technology is complicated and the physical conditions are extremely harsh, resulting in the difficulty of random number generation, the difficulty of technical implementation and the high generation cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0018] Figure 1 is a flow chart of an optional method for generating random numbers according to an embodiment of the present application;
[0019] Figure 2 is a schematic diagram of an optional process of generating random numbers according to an embodiment of the present application;
[0020] Figure 3 is a schematic diagram of an optional model for generating random numbers according to an embodiment of the present application;
[0021] Figure 4 It is a structural schematic diagram of a random number generation device according to an embodiment of the present application. DETAILED DESCRIPTION
[0022] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0023] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0024] According to an embodiment of the present application, an embodiment of a method for generating a random number is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0025] Figure 1 is a method for generating random numbers according to an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:
[0026] Step S102, determining the starting position of the movable reference point;
[0027] Step S104, randomly generating a moving direction and a moving speed of the movable reference point, controlling the movable reference point to move from a starting position along the moving direction at the moving speed, and recording a starting time when the movable reference point moves along the moving direction at the moving speed;
[0028] Step S106, stopping the movement of the movable reference point at any time, determining the end time of the movement of the movable reference point, and determining the difference between the end time and the start time of the movement;
[0029] Step S108, determining the displacement of the movable reference point according to the moving direction, moving speed and difference;
[0030] Step S110, determining a random number according to the displacement, wherein the random number can at least be used to encrypt the data to be encrypted.
[0031] In the random number generation method, the starting position of a movable reference point is determined; the moving direction and moving speed of the movable reference point are randomly generated, the movable reference point is controlled to move from the starting position along the moving direction at the moving speed, and the starting time when the movable reference point moves along the moving direction at the moving speed is recorded; the movement of the movable reference point is stopped at any time, the movement end time of the movable reference point is determined, and the difference between the movement end time and the starting time is determined; the displacement of the movable reference point is determined according to the moving direction, the moving speed and the difference; the random number is determined according to the displacement, wherein the random number can at least be used to encrypt the encrypted data, thereby achieving the technical effect of quickly and conveniently generating random numbers and greatly saving the generation cost, thereby solving the technical problems that the random number generation method in the related technology is complicated and the physical conditions are extremely harsh, resulting in the difficulty of random number generation, the difficulty of technical implementation and the high generation cost.
[0032] In some examples of the present application, before determining the random number according to the displacement, the starting position may be determined as the origin of the plane coordinate system; and the angle between the trajectory corresponding to the displacement and the horizontal axis of the plane coordinate system may be determined.
[0033] In some embodiments, a random number is determined based on a displacement, which can be determined in the following manner: an endpoint coordinate point of a movable reference point in a plane coordinate system is obtained based on the displacement and the angle, wherein the endpoint coordinate point includes: a set of ordered number pairs, wherein a set of ordered number pairs includes: a first element value along the horizontal axis and a second element value along the vertical axis of the plane coordinate system; a random number is obtained based on the first element value and the second element value.
[0034] In some embodiments of the present application, the endpoint coordinate point of the movable reference point in the plane coordinate system is obtained according to the displacement and the angle, including: determining the cosine value corresponding to the angle, and obtaining the first element value according to the product of the cosine value and the displacement; determining the sine value corresponding to the angle, and obtaining the second element value according to the product of the sine value and the displacement.
[0035] Specifically, obtaining a random number based on a first element value and a second element value includes: determining a first square value of the first element value; determining an absolute value of the second element value and a second square value of the second element value; and obtaining a random number based on at least the first element value, the first square value, the absolute value of the second element value and the second square value.
[0036] In some embodiments of the present application, after determining the absolute value of the second element value and the second square value of the second element value, a target symbol can be randomly selected from a symbol list; and a predetermined splicing rule is obtained, wherein the splicing rule is used to indicate the combination order of the first element value, the first square value, the absolute value of the second element value, the second square value, and the target symbol.
[0037] It should be noted that the random number can be obtained at least based on the first element value, the first square value, the absolute value and the second square value. The random number can be obtained by splicing the first element value, the first square value, the absolute value of the second element value, the second square value and the target symbol in a combination order indicated by a predetermined splicing rule.
[0038] Figure 2 This is an optional flow chart of generating random numbers in this application, such as Figure 2 As shown, the process mainly includes: constructing a coordinate system, initializing the origin, obtaining a random direction, obtaining a random distance, determining the end point coordinates, and calculating a random number.
[0039] Specifically, this can be achieved through the following steps:
[0040] 1. Construct a two-dimensional rectangular coordinate system and use the origin as the initial position.
[0041] 2. Randomly determine a random angle in 360 degrees. There are four situations at this time. The angle exists in the first, second, third, and fourth quadrants. And on the X and Y axes.
[0042] 3. The program generates random speeds and random times to calculate the distance and connect the origin to get a unique end point. The end point is perpendicular to the X-axis. Next, we have a right triangle with the three points being the origin, the end point, and the point perpendicular to the X-axis.
[0043] 4. Now we have the length of the hypotenuse and the angle between the hypotenuse and the X axis. The specific coordinates can be obtained based on the sin angle and the cos angle. At this time, the unique (x, y) coordinates are added to the prescribed mathematical calculation to determine a unique set of arrays.
[0044] 5. The 360-degree dotted circle indicates that it may appear in any direction of the 360-degree direction. At this time, it may appear in any of the four quadrants, as well as on the X-axis and Y-axis. The distance s obtained by random v and random time is also random, that is, s=vt. After the random angle and random s are determined, we now have a line segment starting from the origin, which is s. Next, calculate the coordinates of the end point, add sine, cosine and other calculations to get the final random number, and splice X|Y|X2*Y2 to get the random number.
[0045] Figure 3 This is a schematic diagram of an optional model for generating random numbers in this application, such as Figure 3 As shown, the displacement trajectory can be distributed in any quadrant, so on this basis, the random number can be generated in any of the four quadrants.
[0046] It is easy to notice that the random number generation method of the present application has high executability in the program and ensures randomness, while the related technology involves harsh physical conditions and technical factors, which is basically impossible to achieve in actual software applications. Secondly, since the method involves a small amount of data, it is conducive to cross-platform operation written in Java, with fast execution speed and convenient use, and the operating environment is light and simple.
[0047] Figure 4 According to an embodiment of the present application, a random number generating device is provided, such as Figure 4 As shown, the device comprises:
[0048] A first determination module 40, used to determine a starting position of a movable reference point;
[0049] The control module 42 is used to randomly generate a moving direction and a moving speed of the movable reference point, control the movable reference point to move from a starting position along the moving direction at the moving speed, and record a starting moment when the movable reference point moves along the moving direction at the moving speed;
[0050] A second determination module 44 is used to stop the movement of the movable reference point at any time, determine the end time of the movement of the movable reference point, and determine the difference between the end time and the start time of the movement;
[0051] A third determination module 46 is used to determine the displacement of the movable reference point according to the moving direction, the moving speed and the difference;
[0052] The fourth determination module 48 is configured to determine a random number according to the displacement, wherein the random number can at least be used to encrypt the data to be encrypted.
[0053] In the random number generating device, the first determining module 40 is used to determine the starting position of the movable reference point; the control module 42 is used to randomly generate the moving direction and moving speed of the movable reference point, control the movable reference point to start from the starting position, move along the moving direction at the moving speed, and record the starting time of the movable reference point moving along the moving direction at the moving speed; the second determining module 44 is used to stop the movement of the movable reference point at any time, determine the movement end time of the movable reference point, and determine the difference between the movement end time and the starting time; the third determining module 46 is used to determine the displacement of the movable reference point according to the moving direction, the moving speed and the difference; the fourth determining module 48 is used to determine the random number according to the displacement, wherein the random number can at least be used to encrypt the encrypted data, thereby achieving the technical effect of quickly and conveniently generating random numbers and greatly saving the generation cost, thereby solving the technical problems of high difficulty, technical difficulty and high generation cost caused by the complex method of generating random numbers and extremely harsh physical conditions in the related technology.
[0054] According to another aspect of an embodiment of the present application, a non-volatile storage medium is further provided, the non-volatile storage medium including a stored program, wherein when the program is running, the device where the non-volatile storage medium is located is controlled to execute any random number generation method.
[0055] According to another aspect of an embodiment of the present application, a processor is further provided, and the processor is used to run a program, wherein any random number generation method is executed when the program is running.
[0056] Specifically, the above storage medium is used to store program instructions for executing the following functions to achieve the following functions:
[0057] Determine the starting position of the movable reference point; randomly generate a moving direction and a moving speed of the movable reference point, control the movable reference point to move from the starting position along the moving direction at the moving speed, and record the starting time when the movable reference point moves along the moving direction at the moving speed; stop the movement of the movable reference point at any time, determine the movement end time of the movable reference point, and determine the difference between the movement end time and the start time; determine the displacement of the movable reference point according to the moving direction, the moving speed and the difference; determine a random number according to the displacement, wherein the random number can at least be used to encrypt the encrypted data.
[0058] Specifically, the processor is used to call the program instructions in the memory to implement the following functions:
[0059] Determine the starting position of the movable reference point; randomly generate a moving direction and a moving speed of the movable reference point, control the movable reference point to move from the starting position along the moving direction at the moving speed, and record the starting time when the movable reference point moves along the moving direction at the moving speed; stop the movement of the movable reference point at any time, determine the movement end time of the movable reference point, and determine the difference between the movement end time and the start time; determine the displacement of the movable reference point according to the moving direction, the moving speed and the difference; determine a random number according to the displacement, wherein the random number can at least be used to encrypt the encrypted data.
[0060] In the relevant embodiments of the present application, a method of generating random numbers based on physical movement is adopted, by determining the starting position of a movable reference point; randomly generating a moving direction and a moving speed of the movable reference point, controlling the movable reference point to move from the starting position along the moving direction at the moving speed, and recording the starting moment of the movable reference point moving along the moving direction at the moving speed; stopping the movement of the movable reference point at any moment, determining the movement end moment of the movable reference point, and determining the difference between the movement end moment and the starting moment; determining the displacement of the movable reference point according to the moving direction, the moving speed and the difference; determining the random number according to the displacement, thereby achieving the technical effect of quickly and conveniently generating random numbers and greatly saving generation costs, thereby solving the technical problems of difficulty in generating random numbers, technical difficulty in achieving, and high generation costs due to the complex methods for generating random numbers and extremely harsh physical conditions in related technologies.
[0061] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0062] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0063] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0064] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0065] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0066] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0067] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for generating a random number, characterized in that: include: Determine the starting position of the movable reference point; Randomly generate a moving direction and a moving speed of a movable reference point, control the movable reference point to move from the starting position along the moving direction at the moving speed, and record a starting time when the movable reference point moves along the moving direction at the moving speed; Stop the movement of the movable reference point at any time, determine the movement end time of the movable reference point, and determine the difference between the movement end time and the start time; Determine the displacement of the movable reference point according to the moving direction, the moving speed and the difference; Determining a random number according to the displacement includes: obtaining an endpoint coordinate point of the movable reference point in a plane coordinate system according to the displacement and the angle, wherein the endpoint coordinate point includes: a set of ordered number pairs, wherein the set of ordered number pairs includes: a first element value along a horizontal axis and a second element value along a vertical axis of the plane coordinate system; obtaining the random number according to the first element value and the second element value, wherein the random number can at least be used to encrypt data to be encrypted; Before determining the random number according to the displacement, the method further includes: determining the starting position as the origin of the plane coordinate system; determining the angle between the trajectory corresponding to the displacement and the horizontal axis of the plane coordinate system; Wherein, obtaining the end point coordinate point of the movable reference point in the plane coordinate system according to the displacement and the angle includes: determining a cosine value corresponding to the angle, and obtaining the first element value according to the product of the cosine value and the displacement; determining a sine value corresponding to the angle, and obtaining the second element value according to the product of the sine value and the displacement; Obtaining the random number according to the first element value and the second element value includes: determining a first square value of the first element value; determining an absolute value of the second element value and a second square value of the second element value; obtaining the random number according to at least the first element value, the first square value, the absolute value of the second element value, and the second square value, including: splicing the first element value, the first square value, the absolute value of the second element value, the second square value, and a target symbol based on a combination order indicated by a predetermined splicing rule to obtain the random number; Among them, after determining the absolute value of the second element value and the second square value of the second element value, it includes: randomly selecting a target symbol from a symbol list; obtaining the predetermined splicing rule, wherein the splicing rule is used to indicate the combination order of the first element value, the first square value, the absolute value of the second element value, the second square value and the target symbol.
2. A random number generating device, characterized in that: include: A first determination module, used to determine a starting position of a movable reference point; a control module, configured to randomly generate a moving direction and a moving speed of a movable reference point, control the movable reference point to move from the starting position along the moving direction at the moving speed, and record a starting moment when the movable reference point moves along the moving direction at the moving speed; A second determination module is used to stop the movement of the movable reference point at any time, determine the movement end time of the movable reference point, and determine the difference between the movement end time and the start time; A third determination module, configured to determine the displacement of the movable reference point according to the moving direction, the moving speed and the difference; a fourth determination module, configured to determine a random number according to the displacement, comprising: obtaining an endpoint coordinate point of the movable reference point in a plane coordinate system according to the displacement and the angle, wherein the endpoint coordinate point comprises: a set of ordered number pairs, wherein the set of ordered number pairs comprises: a first element value along a horizontal axis and a second element value along a vertical axis of the plane coordinate system; obtaining the random number according to the first element value and the second element value, wherein the random number can at least be used to encrypt data to be encrypted; Before determining the random number according to the displacement, the fourth determination module is further used to: determine the starting position as the origin of the plane coordinate system; determine the angle between the trajectory corresponding to the displacement and the horizontal axis of the plane coordinate system; Wherein, obtaining the end point coordinate point of the movable reference point in the plane coordinate system according to the displacement and the angle includes: determining a cosine value corresponding to the angle, and obtaining the first element value according to the product of the cosine value and the displacement; determining a sine value corresponding to the angle, and obtaining the second element value according to the product of the sine value and the displacement; Obtaining the random number according to the first element value and the second element value includes: determining a first square value of the first element value; determining an absolute value of the second element value and a second square value of the second element value; obtaining the random number according to at least the first element value, the first square value, the absolute value of the second element value, and the second square value, including: splicing the first element value, the first square value, the absolute value of the second element value, the second square value, and a target symbol based on a combination order indicated by a predetermined splicing rule to obtain the random number; Among them, after determining the absolute value of the second element value and the second square value of the second element value, it includes: randomly selecting a target symbol from a symbol list; obtaining the predetermined splicing rule, wherein the splicing rule is used to indicate the combination order of the first element value, the first square value, the absolute value of the second element value, the second square value and the target symbol.
3. A non-volatile storage medium, characterized in that: The non-volatile storage medium includes a stored program, wherein when the program is running, the device where the non-volatile storage medium is located is controlled to execute the random number generation method according to claim 1.
4. A processor, characterized in that: The processor is used to run a program, wherein the random number generation method of claim 1 is executed when the program is run.
