Methods, devices, equipment, and media for generating random sequences
By using historical output values and modulo K operations to generate random sequences in a multi-state machine system, the problem of random sequences being easily predicted in the prior art is solved, and higher security and complexity are achieved.
Patent Information
- Application Number
- CN202180001622.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-25
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2041-06-25
AI Technical Summary
In the prior art, random sequences generated by multi-state machines are easily predicted, resulting in low security in information encryption.
By selecting the state machine in sequence according to the first rule according to the historical output values of multiple state machines, and random sequences are generated using modulo K operations and boundary conditions to increase randomness and complexity.
It improves the randomness and unpredictability of random sequences and enhances the security of information encryption.
Smart Images

Figure CN115735191B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to a method, apparatus, device, and medium for generating a random sequence. Background Art
[0002] Random sequences can be applied in fields such as information encryption.
[0003] In related technologies, random sequences can be generated using multiple state machines. Each state machine can randomly output 0 or 1, and multiple state machines output in a fixed order. The output values of multiple state machines form a random sequence.
[0004] Because multiple state machines output in a fixed order, the generated random sequence is easily predictable, resulting in low security for information encryption using the random sequence. Summary of the Invention
[0005] Embodiments of the present disclosure provide a method, apparatus, device, and medium for generating a random sequence, which can improve the randomness and unpredictability of the generated random sequence.
[0006] In a first aspect, embodiments of the present disclosure provide a method for generating a random sequence. The method is used to generate a random sequence using multiple state machines, and any one of the multiple state machines is used to generate an output value. The method includes: sequentially selecting one state machine from the multiple state machines for output according to the historical output values of at least some of the multiple state machines according to a first rule; obtaining the output values of each state machine; and forming a random sequence from the output values of the multiple state machines according to the output order of the multiple state machines.
[0007] In an implementation manner of the embodiments of the present disclosure, each of the multiple state machines has a number, and the numbers of the multiple state machines are integers and consecutive. The first rule is used to calculate the indication value of a second state machine according to the indication value of a first state machine and the output value of the first state machine. The second state machine is the first state machine among the multiple state machines that outputs after the first state machine.
[0008] In an implementation manner of the embodiments of the present disclosure, the step of sequentially selecting one state machine from the multiple state machines for output according to the historical output values of at least some of the multiple state machines according to the first rule includes: calculating the indication value of the second state machine using the first rule based on the indication value of the first state machine and the output value of the first state machine; determining the number of the second state machine according to the indication value of the second state machine; and controlling the second state machine to output according to the number of the second state machine.
[0009] In one implementation manner of the embodiment of the present disclosure, calculating the indication value of the second state machine according to the indication value of the first state machine and the output value of the first state machine by using the first rule includes: performing a modulo-K operation on the sum of the indication value of the first state machine, the product of the output value of the first state machine and the first parameter value, and the second parameter value to obtain the indication value of the second state machine. Wherein, K is the number of the multiple state machines, the first parameter value is greater than 0 and less than 1, the second parameter value is an integer, and the value range of the second parameter value is [2, 2K - 1].
[0010] In one implementation manner of the embodiment of the present disclosure, determining the number of the second state machine according to the indication value of the second state machine includes: using the integer part of the indication value of the second state machine as the number of the second state machine.
[0011] In one implementation manner of the embodiment of the present disclosure, the method further includes: when a boundary condition is satisfied, controlling the multiple state machines to stop outputting. Wherein, the boundary condition includes: in the set of historical indication values, there is a historical indication value equal to the indication value of the currently output state machine.
[0012] In one implementation manner of the embodiment of the present disclosure, the number of the multiple state machines is 2 t , where t is a positive integer.
[0013] In one implementation manner of the embodiment of the present disclosure, when each state machine outputs for the first time, it randomly selects one of the first value and the second value as the output value for output.
[0014] In a second aspect, an apparatus for generating a random sequence provided by an embodiment of the present disclosure includes: a state module, a selection module, an acquisition module, and a generation module. The state module includes multiple state machines, and any one of the multiple state machines is used to generate an output value. The selection module is configured to sequentially select one state machine from the multiple state machines for output according to the historical output values of at least some of the multiple state machines according to the first rule. The acquisition module is configured to acquire the output values of the respective state machines. The generation module is configured to form a random sequence by using the output values of the multiple state machines in the output order of the multiple state machines.
[0015] In one implementation of the embodiments of the present disclosure, each of the multiple state machines has a number, and the numbers of the multiple state machines are integers and consecutive. The selection module includes: a calculation sub-module, a determination sub-module, and a control sub-module. Among them, the calculation sub-module is used to calculate the indication value of the second state machine according to the indication value of the first state machine and the output value of the first state machine, and the second state machine is the first state machine that outputs after the first state machine among the multiple state machines. The determination sub-module is used to determine the number of the second state machine according to the indication value of the second state machine. The control sub-module is used to control the second state machine to output according to the number of the second state machine.
[0016] In one implementation of the embodiments of the present disclosure, the calculation sub-module is used to perform a modulo K operation on the sum of the product of the indication value of the first state machine, the output value of the first state machine and the first parameter value, and the second parameter value to obtain the indication value of the second state machine. Wherein, K is the number of the multiple state machines, the first parameter value is greater than 0 and less than 1, the second parameter value is an integer, and the value range of the second parameter value is [2, 2K - 1].
[0017] In one implementation of the embodiments of the present disclosure, the determination sub-module is used to use the integer part of the indication value of the second state machine as the number of the second state machine.
[0018] In one implementation of the embodiments of the present disclosure, the device further includes: a stop module, which is used to control the multiple state machines to stop output when the boundary condition is met. Wherein, the boundary condition includes: in the set of historical indication values, there is a historical indication value equal to the indication value of the currently output state machine.
[0019] In one implementation of the embodiments of the present disclosure, the number of the multiple state machines is 2 t , where t is a positive integer.
[0020] In one implementation of the embodiments of the present disclosure, when each state machine outputs for the first time, it randomly selects one of the first value and the second value as the output value for output.
[0021] In a third aspect, an embodiment of the present disclosure provides a computer device, which includes a processor and a memory. Among them, the memory is used to store a computer program; the processor is used to execute the computer program stored in the memory to implement any one of the foregoing methods.
[0022] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, in which computer instructions are stored, and when the stored computer instructions are executed by a processor, any one of the foregoing methods can be implemented.
[0023] The beneficial effects brought by the technical solution provided by the embodiments of the present disclosure are as follows: According to the historical output values of at least some of the multiple state machines, a state machine is sequentially selected from the multiple state machines according to the first rule for output. Since the selection of each state machine is related to the output of the historical state machine of that state machine, therefore, the multiple state machines output are more random, and the random sequence composed of the output values of the multiple state machines is also more random and difficult to predict, improving the security of using the random sequence for information encryption. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present disclosure. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained according to these drawings.
[0025] Figure 1 is a schematic diagram of a random sequence generation method provided by an embodiment of the present disclosure;
[0026] Figure 2 is a flowchart of a method for controlling the output of a state machine provided by an embodiment of the present disclosure;
[0027] Figure 3 is a circuit implementation diagram of a method for controlling the output of a state machine provided by an embodiment of the present disclosure;
[0028] Figure 4 is a schematic diagram of a state machine selection provided by an embodiment of the present disclosure;
[0029] Figures 5 to 10 is a schematic diagram of the probability density distribution of N under different Fs in an example provided by an embodiment of the present disclosure;
[0030] Figures 11 to 16 is a schematic diagram of the probability density distribution of N under different Fs in another example provided by an embodiment of the present disclosure;
[0031] Figure 17 is a schematic diagram of the jump process of a state machine in another example provided by an embodiment of the present disclosure;
[0032] Figure 18 is a schematic diagram of the jump process of a state machine in another example provided by an embodiment of the present disclosure;
[0033] Figure 19 and Figure 20 is a schematic diagram of the probability density distribution of N under different rs in another example provided by an embodiment of the present disclosure;
[0034] Figure 21 It is a schematic structural diagram of a random sequence generation device provided by an embodiment of the present disclosure;
[0035] Figure 22 It is a schematic structural diagram of a computer device provided by an embodiment of the present disclosure. Detailed implementation manners
[0036] To make the objectives, technical solutions, and advantages of the present disclosure clearer, the following will further describe the embodiments of the present disclosure in detail with reference to the accompanying drawings.
[0037] The embodiment of the present disclosure provides a random sequence generation method, which can be applied to fields such as information encryption, fingerprint recognition, and security protection. In the embodiment of the present disclosure, the random sequence is also referred to as a time series.
[0038] Figure 1 It is a schematic diagram of a random sequence generation method provided by an embodiment of the present disclosure. As Figure 1 shown, the method includes:
[0039] In step 101, according to the historical output values of at least some of the multiple state machines, one state machine is sequentially selected from the multiple state machines for output according to the first rule.
[0040] Each state machine is used to generate an output value, for example, 0 or 1.
[0041] Exemplarily, each of the multiple state machines has a number. For example, the numbers of the multiple state machines are consecutive integers, such as state machine 0, state machine 1... state machine N.
[0042] In step 102, obtain the output values of each state machine.
[0043] That is, obtain the output values of the state machines sequentially selected in step 101.
[0044] In step 103, according to the output order of the multiple state machines, form the output values of the multiple state machines into a random sequence.
[0045] According to the historical output values of at least some of the multiple state machines, one state machine is sequentially selected from the multiple state machines for output according to the first rule. Since the selection of each state machine is related to the output of the historical state machine of that state machine, the multiple state machines output are more random. Therefore, the random sequence composed of the output values of the multiple state machines is also more random and difficult to predict, improving the security of using the random sequence for information encryption.
[0046] Figure 2 It is a flowchart of a method for controlling the output of a state machine provided by an embodiment of the present disclosure. AsFigure 2 As shown, the process of the selection state machine includes:
[0047] In step 201, based on the indication value of the first state machine and the output value of the first state machine, the indication value of the second state machine is calculated using the first rule.
[0048] Exemplarily, the first rule is used to calculate the indication value of the second state machine according to the indication value of the first state machine and the output value of the first state machine. The second state machine is the first state machine that outputs after the first state machine among multiple state machines.
[0049] The indication value of each state machine calculated according to this first rule is related not only to the output of the previous state machine but also to the indication value of the previous state machine, increasing the randomness and complexity of the state machine selection, and further increasing the randomness and complexity of the generated random sequence.
[0050] In the embodiments of the present disclosure, the second state machine is relative to the first state machine, and each state machine can be used as the second state machine of another state machine. For example, the output order of multiple state machines is state machine 1, state machine 4, state machine 2. When state machine 1 is the first state machine, the second state machine is state machine 4; when state machine 4 is the first state machine, the second state machine is state machine 2.
[0051] In a possible implementation manner, step 201 includes: performing a modulo K operation on the sum of the indication value of the first state machine, the product of the output value of the first state machine and the first parameter value, and the second parameter value to obtain the indication value of the second state machine. Where K is the number of multiple state machines, the first parameter value is greater than 0 and less than 1, the second parameter value is an integer, and the value range of the second parameter value is [2, 2K - 1].
[0052] By setting different first parameter values and second parameter values, different indication value sequences can be obtained, and further control the output of multiple state machines in different orders, further improving the randomness and complexity of the generated random sequence.
[0053] In some embodiments, the number of multiple state machines is 2 t , t is a positive integer. In other embodiments, the number of multiple state machines can be any positive integer.
[0054] In the embodiments of the present disclosure, when each state machine outputs for the first time, it randomly selects one of the first value and the second value as the output value for output. Subsequently, during the entire process of generating the random sequence, the output value of each state machine remains unchanged. For example, when state machine 3 outputs for the first time, the output value is the first value. Then, when state machine 3 outputs again in the subsequent state machine outputs, the output value of state machine 3 is still the first value.
[0055] Exemplarily, in binary, the first value and the second value are 0 and 1 respectively. The probability of each state machine outputting 0 or 1 is 0.5, satisfying the Bernoulli distribution.
[0056] The calculation process of the indication value of the second state machine will be introduced in detail below with reference to formula (1).
[0057]
[0058] In formula (1), A(n) is the indication value of the (n + 1)-th output state machine, and A(n - 1) is the indication value of the n-th output state machine. That is, A(n - 1) is the indication value of the first state machine, and A(n) is the indication value of the second state machine. A(0) is the indication value of the first state machine, that is, A(0) is the initial value, which can be set according to actual needs. For example, the value range of A(0) is [0, K - 1] and it is an integer. is the output value of the n-th state machine. The output value of each state machine is 0 or 1, and the probability of outputting 0 or 1 is 0.5. r is the first parameter value, and K is the number of multiple state machines. F is the second parameter value, and the value of F is [2, 2K - 1]. modK represents modulo K operation. In the embodiments of the present disclosure, both the first parameter value and the second parameter value can be set according to actual needs.
[0059] Since r is a decimal number and F can also be a decimal number, the calculated A(n) may be either an integer or a decimal number, that is, the indication value of each state machine can be an integer or a decimal number.
[0060] Figure 3 is a circuit implementation diagram of a method for controlling the output of a state machine provided by an embodiment of the present disclosure, as Figure 3 shown. The circuit includes: a pulse signal providing circuit 31, a selection circuit 32, a conversion circuit 33, a multiplier 34, and an adder 35. Among them, the pulse signal providing circuit 31 is used to provide multiple pulse signals for multiple state machines respectively, for example, 2 pulse signals. The selection circuit 32 is used to select one of the pulse signals corresponding to the selected state machine for output based on the indication value of the state machine. The conversion circuit 33 is used to convert the output pulse signal into an output value. The multiplier 34 is used to multiply the output value output by the conversion circuit 33 by the second parameter value, and the adder 35 is used to output the sum of the first parameter value and the product of the output value output by the conversion circuit 33 and the second parameter value to the selection circuit 32 to be accumulated with the indication value of the state machine output last time saved in the selection circuit 32 (that is, the indication value of the first state machine) to obtain a new indication value of the state machine, that is, the indication value of the second state machine.
[0061] Optionally, the selection circuit 32 can be a time-averaged frequency direct period synthesis circuit.
[0062] In another possible implementation, step 201 includes: performing a modulo K operation on the sum of the indicated value of the first state machine, the cumulative value of the product of the historical output value of the first state machine and the first parameter value respectively, and the second parameter value, to obtain the indicated value of the second state machine.
[0063] Where K is the number of multiple state machines, the first parameter value is greater than 0 and less than 1, the second parameter value is an integer, and the value range of the second parameter value is [2, 2K - 1].
[0064] Exemplarily, the indicated value of the second state machine is calculated using the following formula (2):
[0065]
[0066] In formula (2), A(n) is the indicated value of the (n + 1)-th output state machine, and A(n - 1) is the indicated value of the n-th output state machine. That is, A(n - 1) is the indicated value of the first state machine, and A(n) is the indicated value of the second state machine. A(0) is the initial value, which can be set according to actual needs. For example, the value range of A(0) is [0, K - 1] and it is an integer. is the cumulative value of the output values of the state machines for the first n outputs. The output value of each state machine is 0 or 1, and the probabilities of outputting 0 or 1 are both 0.5. r i is the first parameter value, r1 = r2 =... r n . K is the number of multiple state machines. F is the second parameter value, and the value of F is [2, 2K - 1], and modK represents performing a modulo K operation.
[0067] In the embodiments of the present disclosure, both the first parameter value and the second parameter value can be set according to actual needs.
[0068] Because r i is a decimal, and F can also be a decimal, so the calculated A(n) may be either an integer or a decimal, that is, the indicated value of each state machine can be an integer or a decimal.
[0069] In step 202, according to the indicated value of the second state machine, the number of the second state machine is determined.
[0070] Exemplarily, the integer part of the indicated value of the second state machine is used as the number of the second state machine. For example, if the indicated value of the second state machine is 4.5 and the integer part of the indicated value is 4, then the second state machine is state machine 4.
[0071] In step 203, according to the number of the second state machine, the second state machine is controlled to output.
[0072] Based on a method similar to steps 201 - 203, the output of a third state machine can be controlled based on the indication value and output value of a second state machine. Further, the outputs of a fourth state machine, a fifth state machine... an Nth state machine can be obtained.
[0073] Optionally, the method further includes: when a boundary condition is satisfied, controlling multiple state machines to stop outputting. The boundary condition may be that in a set of historical indication values, there exists a historical indication value equal to the indication value of the currently output state machine.
[0074] For example, if the currently output state machine is the (N + 1)th state machine, and if there exists an indication value of the (M + 1)th state machine equal to the indication value of the (N + 1)th state machine, combined with formula (1), that is A(M) = A(N), where M is a positive integer less than N, then the output of the (N + 2)th state machine is no longer controlled. At this time, the output values of the 1st state machine, the 2nd state machine... the (N + 1)th state machine form an (N + 1)-bit random sequence.
[0075] Figure 4 is a schematic diagram of a state machine selection provided by an embodiment of the present disclosure. As Figure 4 shown, assuming there are 4 state machines S(1), S(2), S(3) and S(4), corresponding to 4 outputs 0, 1, 1, 0. The sequence obtained according to the foregoing formula (1) and boundary condition is 00101001. The 4-bit sequence becomes an 8-bit sequence. It can be seen that through the random sequence generation method provided by the embodiment of the present disclosure, the randomness of the state machine output can be increased, thereby increasing the length and complexity of the generated random sequence, making the generated random sequence difficult to predict.
[0076] The effects of the embodiments of the present disclosure will be described below with reference to the foregoing formula (1) and boundary conditions.
[0077] Example 1
[0078] The parameter settings are as follows:
[0079] A(0) = 0, K = 4, r = 0.5, that is, the indication value of the 1st state machine is 0, and a total of 4 state machines are used for output. When the boundary condition is satisfied, N takes the corresponding value, that is, the currently output state machine is the (N + 1)th state machine, and the length of the generated random sequence is N + 1. When F takes different values, the results are as shown in Table 1 below:
[0080] Table 1
[0081]
[0082]
[0083] Figures 5 to 10It is a schematic diagram of the probability density distribution of different F and N in an example provided by an embodiment of the present disclosure. In Table 1, the larger the expected value E(N) of N, the longer the number of bits of the generated random sequence and the higher the complexity. For example, when F = 2, the expected value of N is 5.25, that is, the expected value of the number of bits of the generated random sequence is 5.25. According to the related art, the number of bits of the random sequence output by 4 state machines is 4. It can be seen from Table 1 that except when the expected value corresponding to F = 4 is less than 4, the expected values corresponding to other values of F are all greater than 4, and the average expected value is 5.28125, which is greater than 4. Combining Figures 5 to 10 it can be seen that when other parameters are the same, under different F, the probability density distribution of N is also different and there are large differences. Therefore, even when some parameters are obtained, it is difficult to infer the generated random sequence. It can be seen that through the random sequence generation method provided by the embodiment of the present disclosure, the length and unpredictability of the random sequence can be effectively increased.
[0084] Example 2
[0085] The parameter settings are as follows:
[0086] A(0) = 0, K = 32, r = 0.5, that is, the indication value of the first state machine is 0, and a total of 32 state machines are used for output. When the boundary conditions are met, N takes the corresponding value, that is, the currently output state machine is the (N + 1)-th state machine, and the length of the generated random sequence is N + 1.
[0087] Figures 11 to 16 It is a schematic diagram of the probability density distribution of different F and N in another example provided by an embodiment of the present disclosure. Combining Figures 11 to 16 it can be seen that under different F, the probability distribution of N has great randomness, and the number of bits of the generated random sequence also has great randomness. Even when the initially set parameters are obtained, it is difficult to infer the generated random sequence, which can improve the security of information encryption using this random sequence.
[0088] Figure 17 It is a schematic diagram of the jump process of the state machine in another example provided by an embodiment of the present disclosure. As Figure 17 shown, each vertex corresponds to a state machine, and the specific parameters are set as A(0) = 0, K = 32, r = 0.5, F = 2. The probability of jumping from vertex A to A + F and A + F + 1 is both 0.5. For example, vertex 0 corresponds to the first state machine, and the probability of jumping from vertex 0 to vertex 2 and vertex 3 is both 0.5, that is, when the first state machine is state machine 0, the probability of the second state machine being state machine 2 and state machine 3 is both 0.5.
[0089] Figure 18 It is a schematic diagram of the jump process of the state machine in another example provided by an embodiment of the present disclosure, asFigure 18 As shown, the specific parameters are set as A(0) = 0, K = 32, r = 0.5, F = 3. The probabilities of jumping from vertex A to A + F and A + F + 1 are both 0.5. For example, vertex 0 corresponds to the first state machine, and the probabilities of jumping from vertex 0 to vertex 3 and vertex 4 are both 0.5. That is, when the first state machine is state machine 0, the probabilities of the second state machine being state machine 3 and state machine 4 are both 0.5.
[0090] Example 3
[0091] The parameter settings are as follows:
[0092] A(0) = 0, K = 32, F = 2, that is, the indication value of the first state machine is 0, and a total of 32 state machines are used for output. Formula (4) is the boundary condition. When the boundary condition is satisfied, N takes the corresponding value, that is, the currently output state machine is the (N + 1)-th state machine.
[0093] Figure 19 and Figure 20 are schematic diagrams of the probability density distributions of N under different r in another example provided by the embodiments of the present disclosure. Combining Figure 19 and Figure 20 it can be seen that when other initial parameters except r are the same, by setting different values of r, the obtained probability density distributions of N are different, and the generated random sequences are also different. It can be seen that by setting different r, the randomness and unpredictability of the random sequence can be further increased.
[0094] Figure 21 is a schematic structural diagram of a random sequence generation device provided by the embodiments of the present disclosure. As Figure 21 shown, the device includes: a state module 2101, a selection module 2102, an acquisition module 2103, and a generation module 2104. Among them, the state module 2101 includes multiple state machines, and any one of the multiple state machines is used to generate an output. The selection module 2102 is used to sequentially select a state machine from the multiple state machines for output according to the historical output values of at least some of the multiple state machines according to the first rule. The acquisition module 2103 is used to acquire the output values of each state machine. The generation module 2104 is used to form a random sequence by arranging the output values of the multiple state machines in the output order of the multiple state machines.
[0095] In a possible implementation manner of the embodiment of the present disclosure, each of the multiple state machines has a number, and the numbers of the multiple state machines are integers and consecutive; the selection module 2102 includes: a calculation sub-module 2102a, a determination sub-module 2102b, and a control sub-module 2102c. The calculation sub-module 2102a is configured to calculate the indication value of the second state machine according to the indication value of the first state machine and the output value of the first state machine, where the second state machine is the first state machine that outputs after the first state machine among the multiple state machines. The determination sub-module 2102b is configured to determine the number of the second state machine according to the indication value of the second state machine. The control sub-module 2102c is configured to control the second state machine to output according to the number of the second state machine.
[0096] In a possible implementation manner of the embodiment of the present disclosure, the calculation sub-module 2102a is configured to perform a modulo-K operation on the sum of the product of the indication value of the first state machine, the output value of the first state machine, and the first parameter value, and the second parameter value to obtain the indication value of the second state machine. Wherein, K is the number of the multiple state machines, the first parameter value is greater than 0 and less than 1, the second parameter value is an integer, and the value range of the second parameter value is [2, 2K - 1].
[0097] In a possible implementation manner of the embodiment of the present disclosure, the determination sub-module 2102b is configured to use the integer part of the indication value of the second state machine as the number of the second state machine.
[0098] In a possible implementation manner of the embodiment of the present disclosure, the device further includes: a stop module 2105, configured to control the multiple state machines to stop outputting when a boundary condition is satisfied. Wherein, the boundary condition includes: in the set of historical indication values, there is a historical indication value equal to the indication value of the currently output state machine.
[0099] In a possible implementation manner of the embodiment of the present disclosure, the number of the multiple state machines is 2 t , t is a positive integer.
[0100] In a possible implementation manner of the embodiment of the present disclosure, when each state machine outputs for the first time, it randomly selects one of the first value and the second value as the output value for output.
[0101] It should be noted that: when the above-mentioned random sequence generation device generates a random sequence, only the above-mentioned division of each functional module is used for illustration. In practical applications, the above functions can be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the above-mentioned random sequence generation device provided in the embodiment and the embodiment of the random sequence generation method belong to the same concept, and the implementation process is detailed in the method embodiment, which will not be repeated here.
[0102] Figure 22 is a schematic structural diagram of a computer device provided by an embodiment of the present disclosure. As Figure 22 shown, the computer device 2200 includes a memory 2201 and a processor 2202. Those skilled in the art can understand that Figure 22 the structure of the computer device 2200 shown in
[0103] does not limit the computer device 2200. In practical applications, it may include more or fewer components than those shown, or combine some components, or have different component arrangements.
[0104] The memory 2201 can be used to store computer programs and modules. The memory 2201 mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function, etc. The memory 2201 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state storage devices. Correspondingly, the memory 2201 can also include a memory controller to provide access to the memory 2201 by the processor 2202.
[0105] The processor 2202 executes various functional applications and data processing by running the software programs and modules stored in the memory 2201, such as executing the method provided by the embodiment of the present disclosure.
[0105] In an exemplary embodiment, a computer device is further provided. The computer device includes a processor and a memory; wherein, the memory is used to store a computer program; the processor is used to execute the computer program stored in the memory and can execute the method provided by the embodiment of the present disclosure.
[0106] In an exemplary embodiment, a computer-readable storage medium is further provided. The computer-readable storage medium is a non-volatile storage medium, and a computer program is stored in the computer-readable storage medium. When the computer program in the computer-readable storage medium is executed by a processor, the method provided by the embodiment of the present disclosure can be executed.
[0107] In an exemplary embodiment, a computer program product is further provided. Instructions are stored in the computer program product. When it runs on a computer, the computer can execute the data receiving method provided by the embodiment of the present disclosure.
[0108] Those of ordinary skill in the art can understand that all or part of the steps to implement the above embodiments can be completed by hardware, or can be completed by a program instructing relevant hardware. The program can be stored in a computer-readable storage medium. The above-mentioned storage medium can be a read-only memory, a magnetic disk, an optical disc, etc.
[0109] The foregoing are only alternative embodiments of the present disclosure and are not intended to limit the present disclosure. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present disclosure shall be included within the protection scope of the present disclosure.
Claims
1. A method for generating a random sequence, characterized in that, For generating a random sequence using multiple state machines, any one of the multiple state machines is used to generate an output value, and the method includes: According to the historical output values of at least some of the multiple state machines, select one state machine from the multiple state machines in sequence according to the first rule for output; Obtain the output values of each of the state machines; According to the output order of the multiple state machines, form the output values of the multiple state machines into a random sequence.
2. The method according to claim 1, wherein Each of the multiple state machines has a number, and the numbers of the multiple state machines are integers and consecutive; The first rule is used to calculate the indication value of a second state machine according to the indication value of a first state machine and the output value of the first state machine, and the second state machine is the first state machine that outputs after the first state machine among the multiple state machines; The step of selecting one state machine from the multiple state machines in sequence according to the first rule according to the historical output values of at least some of the multiple state machines includes: Based on the indication value of the first state machine and the output value of the first state machine, calculate the indication value of the second state machine using the first rule; Determine the number of the second state machine according to the indication value of the second state machine; Control the second state machine to output according to the number of the second state machine.
3. The method according to claim 2, characterized in that, The step of calculating the indication value of the second state machine using the first rule based on the indication value of the first state machine and the output value of the first state machine includes: Perform a modulo K operation on the sum of the indication value of the first state machine, the product of the output value of the first state machine and a first parameter value, and a second parameter value to obtain the indication value of the second state machine; Wherein, K is the number of the multiple state machines, the first parameter value is greater than 0 and less than 1, the second parameter value is an integer, and the value range of the second parameter value is [2, 2K - 1].
4. The method according to claim 3, characterized in that, The step of determining the number of the second state machine according to the indication value of the second state machine includes: Use the integer part of the indication value of the second state machine as the number of the second state machine.
5. The method according to any one of claims 2 to 4, characterized in that, The method further includes: When the boundary condition is satisfied, control the multiple state machines to stop outputting; Wherein, the boundary condition includes: in the set of historical indication values, there is a historical indication value equal to the indication value of the currently output state machine.
6. The method according to claim 5, characterized in that, The number of the multiple state machines is 2 t , where t is a positive integer.
7. The method according to any one of claims 1 to 4 or claim 6, characterized in that, When each state machine outputs for the first time, randomly select one of a first value and a second value as the output value for output.
8. An apparatus for generating a random sequence, characterized in that The device includes: A state module, including multiple state machines, and any one of the multiple state machines is used to generate an output value; A selection module, configured to select one state machine from the multiple state machines in sequence according to the historical output values of at least some of the multiple state machines according to the first rule for output; An acquisition module, configured to acquire the output values of each of the state machines; A generation module, configured to form the output values of the multiple state machines into a random sequence according to the output order of the multiple state machines.
9. The device according to claim 8, wherein, Each of the multiple state machines has a number, and the numbers of the multiple state machines are integers and consecutive; the selection module includes: A calculation sub-module, configured to calculate an indication value of a second state machine according to an indication value of a first state machine and an output value of the first state machine, where the second state machine is the first state machine that outputs after the first state machine among the multiple state machines; A determination sub-module, configured to determine a number of the second state machine according to the indication value of the second state machine; A control sub-module, configured to control the second state machine to output according to the number of the second state machine; 10. The device according to claim 9, characterized in that, The calculation sub-module is configured to perform a modulo-K operation on a sum of the indication value of the first state machine, a product of the output value of the first state machine and a first parameter value, and a second parameter value, to obtain the indication value of the second state machine; wherein, K is a number of the multiple state machines, the first parameter value is greater than 0 and less than 1, the second parameter value is an integer, and a value range of the second parameter value is [2, 2K - 1]; 11. The device according to claim 10, characterized in that, The determination sub-module is configured to use an integer part of the indication value of the second state machine as the number of the second state machine; 12. The device according to any one of claims 9 to 11, characterized in that The apparatus further includes: A stop module, configured to control the multiple state machines to stop output when boundary conditions are satisfied; wherein, the boundary conditions include: in a set of historical indication values, there is a historical indication value that is equal to an indication value of a currently output state machine; 13. The device according to claim 12, wherein, The number of the multiple state machines is 2 t , where t is a positive integer.
14. The device according to any one of claims 8 to 11 or claim 13, characterized in that, Each of the state machines randomly selects one of a first value and a second value as the output value to output when outputting for the first time; 15. A computer device, characterized in that, The computer device includes a processor and a memory; wherein, the memory is configured to store a computer program; the processor is configured to execute the computer program stored in the memory to implement the method according to any one of claims 1 to 7; 16. A computer-readable storage medium, characterized in that, Computer instructions are stored in the computer-readable storage medium, and when the stored computer instructions are executed by a processor, the method according to any one of claims 1 to 7 can be implemented.
Citation Information
Patent Citations
Method for generating a random output bit sequence
CN103636159A
Multi-random-source management method of random number generator
CN110502208A