CN110688092B - Random number generation method, device, equipment and storage medium - Google Patents

Random number generation method, device, equipment and storage medium Download PDF

Info

Publication number
CN110688092B
CN110688092B CN201910832113.0A CN201910832113A CN110688092B CN 110688092 B CN110688092 B CN 110688092B CN 201910832113 A CN201910832113 A CN 201910832113A CN 110688092 B CN110688092 B CN 110688092B
Authority
CN
China
Prior art keywords
random number
binary sequence
coding
random
coded
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910832113.0A
Other languages
Chinese (zh)
Other versions
CN110688092A (en
Inventor
王杰林
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hunan Yaosheng Communication Technology Co ltd
Original Assignee
Hunan Yaosheng Communication Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hunan Yaosheng Communication Technology Co ltd filed Critical Hunan Yaosheng Communication Technology Co ltd
Priority to CN201910832113.0A priority Critical patent/CN110688092B/en
Publication of CN110688092A publication Critical patent/CN110688092A/en
Application granted granted Critical
Publication of CN110688092B publication Critical patent/CN110688092B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/58Random or pseudo-random number generators
    • G06F7/588Random number generators, i.e. based on natural stochastic processes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/08Key distribution or management, e.g. generation, sharing or updating, of cryptographic keys or passwords
    • H04L9/0861Generation of secret information including derivation or calculation of cryptographic keys or passwords
    • H04L9/0869Generation of secret information including derivation or calculation of cryptographic keys or passwords involving random numbers or seeds

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Signal Processing (AREA)
  • Computational Mathematics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Mathematical Analysis (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Compression, Expansion, Code Conversion, And Decoders (AREA)

Abstract

The invention provides a random number generation method, a random number generation device, equipment and a storage medium. According to the invention, a binary sequence is generated from the random seeds, and then the binary sequence is subjected to isentropic coding, so that the coded binary sequence reaches a completely random state. Meanwhile, when the isentropic coding is carried out on the binary sequence, the value of a positive real number r is converted by setting the bit length Len of the random number, and then coding is carried out, and finally the invention realizes the random number generation capability of self-adaptive length and achieves the simulation random state. The method can simply and effectively generate the random number with the self-adaptive length according to the binary sequence, and the generated random number reaches a completely random state, and has the characteristics of safety, reliability and unpredictability.

Description

Random number generation method, device, equipment and storage medium
Technical Field
The present invention relates to the field of data security processing, and in particular, to a method, an apparatus, a device, and a storage medium for generating random numbers.
Background
In modern science and technology, random numbers are used everywhere, for example, generation, exchange, authentication, encryption, decryption and the like of keys are related to random numbers; moreover, in an asymmetric key encryption system or other types of security protocols, a secure, reliable and unpredictable random number is required to prevent the system from being cracked. In order to meet the requirements of current artificial intelligence deep learning and big data analysis on higher randomness, a method capable of simply and effectively generating random numbers with adaptive lengths is needed, and the generated random numbers can be proved to be not pseudo-random any more theoretically.
Disclosure of Invention
The invention aims to solve at least one technical problem of pseudo-random in the prior art, and provides a random number generation method, a device, equipment and a storage medium. The random number with the self-adaptive length can be simply and effectively generated, and the generated random number reaches a completely random state.
In a first aspect of the present invention, a random number generation method is provided, including the following steps:
acquiring random seeds, generating a binary sequence from the random seeds, and acquiring the sequence length of the binary sequence;
setting a positive real number r to 2H(X)-LenH (x) is the normalized information entropy of the binary sequence, and Len is the random number bit length of the binary sequence;
for the ith bit symbol x in the binary sequence, according to a coding formula Ri=Ri-1rp(x),Li=Li-1+Ri-1F (x-1, r) is encoded, and L after encoding is outputi(ii) a Wherein the coding variable R is presetiInitial value of (2) and coding variable LiP (x) is the normalized probability of the symbol x, and F (x-1, r) is the non-normalized distribution function of x-1.
Further, the random seed is generated from at least one of a system time, a memory pointer, and a last random number.
Further, the encoding variable RiInitial value R of01 is ═ 1; the coding variable LiInitial value L of0=0。
In a second aspect of the present invention, there is provided a random number generation apparatus, including: a preprocessing unit and an encoding unit;
the preprocessing unit is used for acquiring a random seed, generating the random seed into a binary sequence, acquiring a sequence length L of the binary sequence and setting a positive real number r to be 2H(X)-LenH (x) is the normalized information entropy of the binary sequence, and Len is the random number bit length of the binary sequence;
the coding unit is used for coding the ith bit symbol x in the binary sequence according to a coding formula Ri=Ri-1rp(x),Li=Li-1+Ri-1F (x-1, r) is encoded, and L after encoding is outputi(ii) a Wherein the coding variable R is presetiInitial value of (2) and coding variable LiP (x) is the normalized probability of the symbol x, and F (x-1, r) is the non-normalized distribution function of x-1.
In a third aspect of the invention, there is provided a random number generating device comprising at least one control processor and a memory for communicative connection with the at least one control processor; the memory stores instructions executable by the at least one control processor to enable the at least one control processor to perform a method of random number generation according to the first aspect of the invention.
In a fourth aspect of the present invention, there is provided a computer-readable storage medium having stored thereon computer-executable instructions for causing a computer to perform a method of generating random numbers according to the first aspect of the present invention.
The random number generation method, the random number generation device, the random number generation equipment and the storage medium provided by the invention at least have the following beneficial effects:
according to the invention, a binary sequence is generated from the random seeds, then the binary sequence is subjected to isentropic coding, and the coded binary sequence reaches a completely random state. Meanwhile, when the isentropic coding is carried out on the binary sequence, the value of a positive real number r is converted by setting the bit length Len of the random number, and then coding is carried out, and finally the method realizes the random number generation capability of self-adaptive length and achieves the simulation random state. In conclusion, the method can simply and effectively generate the random number with the self-adaptive length according to the binary sequence, and the generated random number reaches a completely random state, and has the characteristics of safety, reliability and unpredictability.
Drawings
The invention is further described below with reference to the accompanying drawings and examples;
fig. 1 is a schematic flow chart illustrating a random number generation method according to a first embodiment of the present invention;
fig. 2 is a schematic structural diagram of a random number generating apparatus according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of a random number generating device according to a third embodiment of the present invention.
Detailed Description
Reference will now be made in detail to the present preferred embodiments of the present invention, examples of which are illustrated in the accompanying drawings, wherein like reference numerals refer to like elements throughout.
Referring to fig. 1, a first embodiment of the present invention provides a random number generation method, including the steps of:
s100, combining the system time, the memory pointer and the last random number as a random seed, converting the random seed into a binary sequence, and acquiring the length L of the binary sequence;
s200, setting a positive real number r to be 2H(X)-LenH (x) is the normalized information entropy of the binary sequence, Len is the random number bit length of the binary sequence;
s300, coding an ith bit symbol, and if the ith bit symbol is a symbol 0, entering the step S400; if the ith symbol is symbol 1, go to step S500;
s400, substituting the symbol 0 into a coding formula to obtain Ri=Ri-1rp (0), L since F (-1, r) ═ 0i=Li-1And proceeds to step S600;
s500, substituting the symbol 1 into a coding formula to obtain Ri=Ri-1rp (1), F (0, r) ═ rp (0), so Li=Li-1+Ri- 1rp (0), and proceeds to step S600;
s600, if the loop variable i is i +1, if i is less than or equal to L, the process proceeds to step S300; if i is more than L, the coding is finished, and V is output, wherein V is L after the binary sequence is codediThe value of (c).
Wherein the coding formula is
Figure BDA0002191057490000031
Li=Li-1+Ri-1F (x-1, r); initial value R of coding variable0=1,L00. The procedure for this example is as follows:
let the discrete random variable x have a fixed normalized probability p (x), and have a positive real number r acting on the normalized probability p (x) at any time, and mark the non-normalized probability of the discrete random variable x as
Figure BDA0002191057490000041
The following formula is satisfied:
Figure BDA0002191057490000042
the sum of the probabilities of all variables at any time is then:
Figure BDA0002191057490000043
k is the number of variables, when r is 1,
Figure BDA0002191057490000044
and is
Figure BDA0002191057490000045
Assuming that the distribution function of the non-normalized probability model is F (x, r), F (x) is the distribution function of the normalized probability model, and s ∈ {0, 1.. k }, then:
Figure BDA0002191057490000046
let R0=1,L0The calculation formula of the i-th bit symbol entropy coding is as follows:
Figure BDA0002191057490000047
Li=Li-1+Ri-1F(x-1,r) (1-5)
according to the information entropy theory, the size of the probability of a symbol determines the size of its self-information volume, i.e. the self-information volume i (x) with a symbol x having a probability p (x) is:
I(x)=log p(x) (1-6)
the units of the self information quantity I (x) are related to the used logarithmic base numbers, the commonly used logarithmic base number in the information theory is 2, the units corresponding to the self information quantity are bits (bit), and therefore, the information entropy is:
Figure BDA0002191057490000048
Figure BDA0002191057490000049
from the above, the information entropy formula of the normalized probability model of the independent discrete binary sequence is as follows:
H(X)=-p(0)log2 p(0)-p(1)log2 p(1) (1-9)
where the unit of H (X) is a bit. The information entropy formula of the non-normalized probability model of the binary sequence is as follows:
Figure BDA00021910574900000410
where the unit of H (X, r) is a bit, and the bit length of the random number is Len, Len ═ H (X, r) can be obtained:
Figure BDA0002191057490000051
since p (0) + p (1) ═ 1, the simplified equation can be found:
Len=-log2 r+H(X) (1-12)
r=2H(X)-Len (1-13)
obviously, h (x) is obtained by the probability of an independent discrete binary sequence symbol, Len is the bit length of a set random number, and the binary sequence length after coding can also be Len by substituting r, p (0), and p (1) into formulas (1-3), (1-4), and (1-5) according to the information entropy theory;
in this embodiment, first, system time, a memory pointer and a previous random number are obtained as random seeds, the random seeds are generated into a binary sequence, then, the binary sequence is subjected to isentropic coding, and according to the information entropy theory, when the binary sequence reaches entropy through coding, the coded binary sequence reaches the most chaotic state, that is, a completely random state. Meanwhile, in the embodiment, when the isentropic coding is performed on the binary sequence, the value of the positive real number r is converted by setting the bit length Len of a required random number, namely, the positive real number r is set, so that the positive real number meets the formula (1-13), then, the coding processing is performed, and finally, the random number generation capability of the self-adaptive length is realized, so that the simulation random state is achieved, and the generated random number has the characteristics of safety, reliability and unpredictability.
It should be understood that in the present embodiment, the first point, L0To LiOnly iterative calculation variables in the encoding process are used, encoding is finished only when the value of a loop variable i is greater than the length L of the binary sequence, and V is the value after the last bit of symbol is encoded, namely Li. Second, the binary sequence may be generated from at least one of the system time, the memory pointer and the last random number, for example, directly from the last random number, or from a combination of the memory pointer and the last random number.
Further, referring to fig. 2, a second embodiment of the present invention provides a random number generation apparatus 1000, including: a preprocessing unit 1100 and an encoding unit 1200;
the preprocessing unit 1100 is configured to obtain a random seed, generate a binary sequence from the random seed, obtain a sequence length L of the binary sequence, and set a positive real number r to 2H(X)-LenH (x) is the normalized information entropy of the binary sequence, Len is the random number bit length of the binary sequence;
the encoding unit 1200 is configured to encode the ith bit symbol x in the binary sequence according to the encoding formula Ri=Ri-1rp(x),Li=Li-1+Ri-1F (x-1, r) is encoded, and L after encoding is outputi(ii) a Wherein the coding variable R is presetiInitial value of (2) and coding variable LiP (x) is the normalized probability of the symbol x in the binary sequence, F (x-1, r) is the non-normalized probability of the symbol x-1 in the binary sequenceA distribution function.
It should be noted that, since one random number generation apparatus in the present embodiment is based on the same inventive concept as the above-mentioned one random number generation method, the corresponding contents in the method embodiment are also applicable to the present apparatus embodiment, and are not described in detail herein.
Further, referring to fig. 3, a third embodiment of the present invention provides a random number generating device, and the random number generating device 200 may be any type of smart terminal, such as a mobile phone, a tablet computer, a personal computer, and the like.
Specifically, the random number generation device 200 includes: one or more control processors 201 and a memory 202, and the present implementation takes one control processor 201 as an example. The control processor 201 and the memory 202 may be connected by a bus or other means, and the present embodiment is exemplified by being connected by a bus.
The memory 202, which is a non-transitory computer-readable storage medium, may be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as program instructions/modules corresponding to the random number generation apparatus in the embodiments of the present invention. Such as the preprocessing unit 1100 and the encoding unit 1200 shown in fig. 2; the control processor 201 executes various functional applications and data processing of the random number generation apparatus 1000, i.e., the random number generation method of the above-described method embodiment, by running non-transitory software programs, instructions and modules stored in the memory 202.
The memory 202 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the stored data area may store data created according to the use of the random number generating apparatus 1000, and the like. Further, the memory 202 may include high speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some embodiments, the memory 202 may optionally include memory located remotely from the control processor 201, which may be connected to the random number generating device 200 via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The one or more modules are stored in the memory 202 and, when executed by the one or more control processors 201, perform the random number generation method of the above-described method embodiments.
Embodiments of the present invention also provide a computer-readable storage medium, which stores computer-executable instructions, which are executed by one or more control processors 201, for example, a control processor 201 executes the random number generation method in the above method embodiments.
The above-described embodiments of the apparatus are merely illustrative, wherein the units illustrated as separate components may or may not be physically separate, i.e. may be located in one place, or may also be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
Through the above description of the embodiments, those skilled in the art can clearly understand that the embodiments can be implemented by software plus a general hardware platform. Those skilled in the art will appreciate that all or part of the processes in the methods of the above embodiments may be implemented by hardware related to instructions of a computer program, which may be stored in a computer readable storage medium, and when executed, may include processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read Only Memory (ROM), a Random Access Memory (RAM), or the like.
The embodiments of the present invention have been described in detail with reference to the accompanying drawings, but the present invention is not limited to the above embodiments, and various changes can be made within the knowledge of those skilled in the art without departing from the gist of the present invention.

Claims (6)

1. A random number generation method, comprising the steps of:
acquiring random seeds, generating a binary sequence from the random seeds, and acquiring the sequence length of the binary sequence;
setting a positive real number r to 2H(X)-LenH (x) is the normalized information entropy of the binary sequence, and Len is the random number bit length of the binary sequence;
for the ith bit symbol x in the binary sequence, according to a coding formula Ri=Ri-1rp(x),Li=Li-1+Ri-1F (x-1, r) is coded until all symbols in the binary sequence are coded, and L coded by the last bit symbol of the binary sequence is outputiL after the last bit symbol of the binary sequence is codediAs a random number; wherein the coding variable R is presetiInitial value of (2) and coding variable LiP (x) is the normalized probability of the symbol x, and F (x-1, r) is the non-normalized distribution function of x-1.
2. The method of claim 1, wherein the random seed is generated from at least one of a system time, a memory pointer, and a last random number.
3. The method of claim 1, wherein the encoding variable R is a variable of a random numberiInitial value R of01 is ═ 1; the coding variable LiInitial value L of0=0。
4. A random number generation apparatus, comprising: a preprocessing unit and an encoding unit;
the preprocessing unit is used for acquiring a random seed, generating the random seed into a binary sequence, acquiring a sequence length L of the binary sequence and setting a positive real number r to be 2H(X)-LenH (X) is the normalized information entropy of the binary sequence, Len is the binary sequenceA random number bit length of the sequence;
the coding unit is used for coding the ith bit symbol x in the binary sequence according to a coding formula Ri=Ri-1rp(x),Li=Li-1+Ri-1F (x-1, r) is coded until all symbols in the binary sequence are coded, and L coded by the last bit symbol of the binary sequence is outputiL after the last bit symbol of the binary sequence is codediAs a random number; wherein the coding variable R is presetiInitial value of (2) and coding variable LiP (x) is the normalized probability of the symbol x, and F (x-1, r) is the non-normalized distribution function of x-1.
5. A random number generating device comprising at least one control processor and a memory for communicative connection with the at least one control processor; the memory stores instructions executable by the at least one control processor to enable the at least one control processor to perform a method of random number generation as claimed in any one of claims 1 to 3.
6. A computer-readable storage medium characterized by: the computer-readable storage medium stores computer-executable instructions for causing a computer to perform a random number generation method as claimed in any one of claims 1 to 3.
CN201910832113.0A 2019-09-04 2019-09-04 Random number generation method, device, equipment and storage medium Active CN110688092B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910832113.0A CN110688092B (en) 2019-09-04 2019-09-04 Random number generation method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910832113.0A CN110688092B (en) 2019-09-04 2019-09-04 Random number generation method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN110688092A CN110688092A (en) 2020-01-14
CN110688092B true CN110688092B (en) 2021-08-17

Family

ID=69107803

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910832113.0A Active CN110688092B (en) 2019-09-04 2019-09-04 Random number generation method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110688092B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113297591B (en) * 2021-05-07 2022-05-31 湖南遥昇通信技术有限公司 Webpage resource encryption method, equipment and storage medium
CN113608951B (en) * 2021-07-27 2023-10-03 际络科技(上海)有限公司 Chip state detection method and system, electronic device and readable storage medium

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100480787B1 (en) * 2001-11-27 2005-04-07 삼성전자주식회사 Encoding/decoding method and apparatus for key value of coordinate interpolator node
US7565018B2 (en) * 2005-08-12 2009-07-21 Microsoft Corporation Adaptive coding and decoding of wide-range coefficients
US20130003823A1 (en) * 2011-07-01 2013-01-03 Kiran Misra System for initializing an arithmetic coder
US8933826B2 (en) * 2013-03-01 2015-01-13 Gurulogic Microsystems Oy Encoder apparatus, decoder apparatus and method
US9999788B2 (en) * 2014-06-05 2018-06-19 International Business Machines Corporation Fast and accurate proton therapy dose calculations
CN105515765B (en) * 2015-12-09 2018-08-10 西安电子科技大学 The biological secret key generation method of adaptive dynamic quantization
CN105791832B (en) * 2016-03-08 2019-02-01 湖南千年华光软件开发有限公司 Data-encoding scheme and data decoding method and its system
CN106815860B (en) * 2017-01-17 2019-11-29 湖南优象科技有限公司 A kind of method for tracking target based on orderly comparison feature
CN107301033B (en) * 2017-06-13 2021-09-17 复旦大学 Method for testing maximum entropy rate of true random number generator
CN107666324B (en) * 2017-09-18 2021-01-01 北京航空航天大学 Polar code and arithmetic coding combined information source lossy compression coding method

Also Published As

Publication number Publication date
CN110688092A (en) 2020-01-14

Similar Documents

Publication Publication Date Title
CN110717151B (en) Digital fingerprint processing and signature processing method
CN109658078B (en) Block chain private key generation method, device and medium based on biological characteristics
JP6606169B2 (en) Information encryption and decryption
CN110019216B (en) Intellectual property data storage method, medium and computer device based on block chain
CN110688092B (en) Random number generation method, device, equipment and storage medium
CN110635807B (en) Data coding method and decoding method
CN111461952A (en) Image encryption method, computer device, and computer-readable storage medium
CN116781420B (en) Electronic file secure transmission encryption method and system
CN113300830A (en) Data transmission method, device and storage medium based on weighted probability model
CN113486369A (en) Encoding method, apparatus, device and medium with symmetric encryption and lossless compression
CN113626645B (en) Hierarchical optimization efficient ciphertext fuzzy retrieval method and related equipment
CN111222177A (en) Digital fingerprint processing and signature processing method
CN111447063B (en) Method and device for generating cold wallet derived key
CN112711648A (en) Database character string ciphertext storage method, electronic device and medium
CN116825259A (en) Medical data management method based on Internet of things
CN109951417B (en) Identity authentication method, system and terminal equipment
CN113922947B (en) Self-adaptive symmetrical coding method and system based on weighted probability model
CN114065269B (en) Method for generating and analyzing bindless heterogeneous token and storage medium
CN112634492B (en) Intelligent door lock encryption method and equipment based on Jilin code and storage medium
CN112118087A (en) Cross-chain contract compression encryption system and method
CN115801258B (en) Data processing method, device, electronic equipment and computer readable storage medium
CN115296879B (en) Encryption authentication method and system for microservice
CN117974833B (en) Image generation method, apparatus, device, readable storage medium, and program product
CN113746599B (en) Encoding method, decoding method, terminal, electronic device, and storage medium
CN117057804B (en) Financial transaction data secure storage method and system based on hash sequence

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant