Sampling rejection method with recycling function and electronic equipment
Through the rejection sampling method with recycling, the problem of waste of computing resources and sample independence caused by the sample space not being a power of 2 in the prior art is solved, and more efficient pseudo-random input usage and sample distribution consistency is achieved, which improves the subsequent The operation efficiency of quantum cryptography algorithm.
Patent Information
- Application Number
- CN202411121481.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-15
- Publication Date
- 2024-11-26
AI Technical Summary
When using the existing grid-based ciphers to generate samples that meet the specified distribution, when using the rejection sampling technique, the sample space is not a power of 2, resulting in wasted computing resources, and the samples are not independent, which affects the efficiency of the cipher algorithm.
The rejection sampling method with recycling is used to determine whether the target distribution conditions are met by inputting the bit string. If it is not met, some bit strings will be recycled and reused to ensure sample independence and distribution compliance, and to reduce the use of pseudo-random input.
It effectively reduces the amount of pseudo-random mechanism in the cryptographic algorithm, improves the operation efficiency of the post-quantum cryptographic algorithm, and ensures the independence and distribution consistency of the generated samples.
Smart Images

Figure CN119030715A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of quantum computing technology, and in particular to a rejection sampling method with recycling and an electronic device. Background Art
[0002] The development of quantum computing poses a serious threat to traditional public-key cryptography, such as RSA, DSA, and ECC. Therefore, future cybersecurity urgently requires cryptographic technologies that can resist quantum computing attacks, known as post-quantum cryptography. Lattice cryptography holds a dominant position within post-quantum cryptography due to its theoretically provable security and combined advantages in space and time resources.
[0003] In existing lattice-based cryptography, generating a probability distribution that conforms to a specified distribution or requirement is an extremely important basic operation in cryptographic algorithms. One widely used operation is to generate a matrix or a polynomial whose coefficients follow a uniform distribution within a specified range.
[0004] Cryptographic algorithms typically use a specified pseudorandom mechanism to generate a pseudorandom byte string. This pseudorandom byte string is then used as input to obtain samples from a specified distribution using a sampling algorithm. When the number of elements in the uniform distribution is not a power of 2, the sampling algorithm often uses rejection sampling.
[0005] Note that when the sample space is not a power of 2, the above-mentioned uniformly distributed rejection sampling algorithm will discard (pseudo) random bits that do not meet the requirements. Since the computing resources consumed in producing pseudo-random byte strings account for a considerable proportion in post-quantum cryptographic algorithms, reducing the rejection probability and reducing the demand for using (pseudo)random byte strings are important links in improving the overall efficiency of cryptographic algorithms. Summary of the Invention
[0006] The technical problem to be solved by the present invention is how to ensure that the generated samples obey the specified distribution and that each sample is independent of each other, while reducing the (pseudo) random input used by the sampling algorithm, thereby reducing the amount of (pseudo) random mechanism computation used by the cryptographic algorithm; in view of this, the present invention provides a rejection sampling method and electronic device with recycling.
[0007] The technical solution adopted by the present invention is a rejection sampling method with recovery, comprising:
[0008] Step A1: inputting a bit string of sufficient length, wherein the bit string is a random bit string or a pseudo-random bit string;
[0009] Step A2: If the bit string of the preset length meets the target distribution requirement, then accept a sample of the processed output, discard the used bit string, and proceed to step A4; if the bit string of the preset length does not meet the target distribution requirement, then proceed to step A3;
[0010] Step A3: Extract an independently and uniformly distributed bit string from the bit string of the preset length used in Step A2, recycle it as the input of Step A2 or as part of the input (allowing the length of the recycled bit string to be 0 under some conditions), discard the unextracted bit string, and go to Step A2;
[0011] Step A4: If the number of output samples does not meet the requirement, go to Step A2; if the number of output samples meets the requirement, end.
[0012] In one embodiment, denotes the ring of residue classes modulo a positive integer q, where the addition and multiplication of elements are performed modulo q. For uniform distribution sampling on, the method includes:
[0013] Step B2, take λ bits b0, b1,..., b λ-1 from the given bit string to form a non-negative integer If b < q, then output b as a sample uniformly distributed on, discard the used b0, b1,..., b λ-1 , and go to Step B4; if the determination condition is not satisfied, go to Step B3;
[0014] Step B3, extract an independently and uniformly distributed bit string from the bit string used in Step B2, recycle it and count it as the available bits for Step B2 to use, and go to Step B2;
[0015] Step B4: If the number of output samples does not meet the requirement, go to Step B2; if the number of output samples meets the requirement, end.
[0016] In one embodiment, Step B3 includes:
[0017] Step C1: Take λ bits b0, b1,..., b λ-1 from the given bit string to form a non-negative integer b = b0 + 2·b1 +... + 2 λ-1 ·b λ-1 ≥ q, take the high-order segment of η bits b λ-1 , b λ-2 ,..., b λ-η , where 1 < η < λ and q λ-1 , q λ-2 ,..., q λ-η are not all 1;
[0018] Step C2: Determine whether the integer formed by η bits b λ-1 , b λ-2 ,..., b λ-η is Relationship with an integer If c > d, select some or all of the λ - η bits b0, b1, …, b λ-η-1 and recycle them into the available bits for use in step B2 of the sampling algorithm, then proceed to step B2.
[0019] In one embodiment, step B3 includes:
[0020] Step D1: Take λ bits b0, b1, …, b from the given bit string λ-1 to form a non - negative integer s = b0 + 2·b1 + … + 2 λ-1 ·b λ-1 ≥ q. Take the high - order η bits b λ-1 , b λ-2 , …, b λ-η , where 1 < η < λ and q λ-1 , q λ-2 , …, q λ-η are not all 1;
[0021] Step D2: For determine the set L. The elements of set L consist of one or several integers greater than d. Judge the relationship between the integer formed by the η bits b λ-1 , b λ-2 , …, b λ-η and set L; if c belongs to set L, select some or all of the λ - η bits b0, b1, …, b λ-η-1 and recycle them into the available bits for use in step B2 of the sampling algorithm, then proceed to step B2. λ-η-1
[0022] In one embodiment, step B3 includes:
[0023] Step Z1: Find integers k, l such that 0 ≤ k < l < λ and q k , q k+1 , …, q l-1 are all equal to 0;
[0024] Step Z2: Take λ bits b0, b1, …, b from the given bit string λ-1 to form a non - negative integer s = b0 + 2·b1 + … + 2 λ-1 ·b λ-1 ≥ q. Judge the relationship between the high - order λ - l bits q λ-1 , q λ-2 , …, q l+1 , q l and b λ-1 , b λ-2,…,b l+1 ,b l The relationship: If q satisfies λ-1 =b λ-1 , q λ-2 =b λ-2 ,…, q l+1 =b l+1 , q l =b l , go to step Z3;
[0025] Step Z3: If k>0, determine the relationship between the low-order k bits q k-1 , q k-2 ,…, q0 and b k-1 , b k-2 ,…, b0: If q k-1 =b k-1 , q k-2 =b k-2 ,…, q0 = b0, select some or all of the l-k bits b k , b k+1 ,…, b l-1 and recycle them into the available bits for use in step B2 of the sampling algorithm.
[0026] In one embodiment, if there is a positive integer m in the sample space and a sampling 0≤s<m, the method includes:
[0027] Step E1: Set the sampling space to have at least v bits of complete information, that is
[0028] Step E2: According to the binary representation of the non-negative integer s where s0, s1,…, s ν-1 , s v ∈{0,1}, if s<2 ν , extract some or all of the low-order ν bits e0, e1,…, e ν-1 from the non-negative integer s and recycle them into the available bits for use in step B2 of the sampling algorithm. If s≥2 ν , then the current recycling fails and go to step B2.
[0029] In one embodiment, the step B3 includes:
[0030] Step F1: Take λ bits b0, b1,…, b λ-1 from the given bit string to form a non-negative integer s = b0 + 2·b1 +…+ 2 λ-1 ·b λ-1 ≥q, discard the used b0, b1,…, b λ-1, take the complementary space sampling e=sq caused by rejection;
[0031] Step F2: For the sample space positive integer 2 λ -q and a sample e, run steps E1 and E2.
[0032] In one embodiment, step F2 includes:
[0033] Step G1: For the sample space positive integer 2 λ -q and a sample e, run steps E1 and E2; if the current recovery fails during step E2, then for the sample space positive integer and a sample Run step E1 and step E2;
[0034] Step G2: If the current recovery fails when executing step E2, return to step B2, or use the methods of steps E1 and E2 to recover bits.
[0035] Another aspect of the present invention provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the rejection sampling method with recovery as described in any one of the above items.
[0036] Another aspect of the present invention further provides a computer storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the rejection sampling method with recovery as described in any one of the above items are implemented.
[0037] Compared with the prior art, the present invention has at least the following advantages:
[0038] The present invention provides a rejection and recovery mechanism for algorithms that reject sampling to generate specified distributions, ensuring that the generated samples obey the specified distribution and that each sample is independent of each other. At the same time, it reduces the (pseudo) random input used by the sampling algorithm, thereby reducing the amount of (pseudo) random mechanism computation used by the cryptographic algorithm. This rejection sampling method with recovery can be used to improve the operating efficiency of post-quantum cryptographic algorithms. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 Schematic diagram of a rejection sampling method with recovery according to an embodiment of the present invention;
[0040] Figure 2 FIG. 1 is a schematic diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0041] In order to further illustrate the technical means and effects adopted by the present invention to achieve the predetermined purpose, the present invention is described in detail below with reference to the accompanying drawings and preferred embodiments.
[0042] Unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by those skilled in the art to which this application belongs. It should also be understood that terms (such as those defined in commonly used dictionaries) should be interpreted as having a meaning consistent with their meaning in the context of the relevant technology and will not be interpreted in an idealized or overly formal sense unless expressly defined as such herein.
[0043] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in this application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0044] In an embodiment of the present invention, a rejection sampling method with recovery is provided, such as Figure 1 As shown, including:
[0045] Step A1: inputting a bit string of sufficient length, wherein the bit string is a random bit string or a pseudo-random bit string;
[0046] Step A2: If the bit string of the preset length meets the target distribution requirement, then accept a sample of the processed output, discard the used bit string, and proceed to step A4; if the bit string of the preset length does not meet the target distribution requirement, then proceed to step A3;
[0047] Step A3: extracting independent and uniformly distributed bit strings from the bit string of the preset length used in Step A2, recycling them as input to Step A2 or as part of the input (under some conditions, the length of the recycled bit string is allowed to be 0), discarding the unextracted bit strings, and proceeding to Step A2;
[0048] Step A4: If the number of output samples does not meet the requirement, go to step A2; if the number of output samples meets the requirement, end.
[0049] refer to Figure 1 , the method provided in this embodiment will be described in detail below.
[0050] For ease of understanding, the following symbols are used throughout this document:
[0051] For any real number x, represents the largest integer not greater than x, Represents the smallest integer not less than x. Positive integer modulo q; represents the remainder class ring modulo q, where element addition and multiplication are performed modulo q; λ represents all The number of bits of the element in, that is When q is not a power of 2, the binary bit string of q with the highest bit on the left and the lowest bit on the right is denoted as q λ- 1q λ-2 …q1q0, that is, q = 2 λ-1 ·q λ-1 +2 λ-2 ·q λ-2 +…+2·q1 + q0, where q0, q1, …, q λ-2 , q λ-1 ∈{0, 1}.
[0052] The technical solution adopted by the present invention to solve the rejection sampling technical problem is: A rejection sampling method with recycling, which may include the following steps:
[0053] Step A1: Input a (pseudo) random bit string of sufficient length.
[0054] Step A2: Make a processing decision on a (pseudo) random bit string of appropriate length to determine whether it meets the decision condition of the distribution requirement. If it meets the decision condition, then accept a sample output by the processing, discard the used (pseudo) random bit string, and enter Step A4; if it does not meet the decision condition, enter Step A3.
[0055] Step A3: Extract an independent and uniformly distributed (pseudo) random bit string from the (pseudo) random bit string of appropriate length used in Step A2, recycle it as the input of the sampling algorithm for use in Step A2. Enter Step A2.
[0056] Step A4: If the number of output samples does not meet the requirement, enter Step A2; if the number of output samples meets the requirement, end.
[0057] Further, for uniform distribution sampling on, this embodiment may further include the following steps:
[0058] Step B1: Input a (pseudo) random bit string of sufficient length as the available bit string.
[0059] Step B2: Take λ bits b0, b1, …, b in the given bit string λ-1 to form a non - negative integer If b < q, then output b as a sample uniformly distributed on, discard the used b0, b1, …, b λ-1 , and enter Step B4; if the decision condition is not met, enter Step B3.
[0060] Step B3: Extract independent and uniformly distributed (pseudo)random bit strings from the (pseudo)random bit string of appropriate length used in step B2, recycle and count them into the available bits for use in step B2 of the sampling algorithm. Go to step B2.
[0061] Step B4: If the number of output samples does not meet the requirement, go to step B2; if the number of output samples meets the requirement, end.
[0062] In this embodiment, the above step B3 may further include the following steps:
[0063] Step C1: It is known that in the given bit string, take λ bits b0, b1, ..., b λ-1 Form a non-negative integer b=b0+2·b1+…+2 λ-1 b λ-1 ≥q. Take the high-order segment of η bits b λ-1 ,b λ-2 ,…,b λ-η , where 1<η<λ and q λ-1 ,q λ-2 ,…,q λ-η Not all are 1.
[0064] Step C2: Determine n bits b λ-1 ,b λ-2 ,…,b λ-η Integer composed of With integers If c>d, then from λ-η bits b0,b1,…,b λ-η-1 Select some or all of the recovered bits and count them into the available bits for use in step B2 of the sampling algorithm. Go to step B2.
[0065] In this embodiment, the above step B3 may further include the following steps:
[0066] Step D1: It is known that in the given bit string, take λ bits b0, b1, ..., b λ-1 Form a non-negative integer s=b0+2·b1+…+2 λ-1 b λ-1 ≥q. Take the high-order segment of η bits b λ-1 ,b λ-2 ,…,b λ-η , where 1<η<λ and q λ-1 ,q λ-2 ,…,q λ-η Not all are 1.
[0067] Step D2: Target Determine the set L, whose elements consist of one or several integers greater than d. Judge the relationship between the integer formed by η bits b λ-1 , b λ-2 , …, b λ-η and the set L. If c belongs to the set L, then select some or all of the λ - η bits b0, b1, …, b λ-η-1 for recycling and count them as available bits for use in step B2 of the sampling algorithm. Proceed to step B2.
[0068] In this embodiment, the above step B3 may further include the following steps:
[0069] Step Z1: Find integers k and l satisfying 0 ≤ k < l < λ such that q k , q k+1 , …, q l-1 are all equal to 0.
[0070] Step Z2: Given that λ bits b0, b1, …, b λ-1 are taken from the given bit string to form a non - negative integer s = b0 + 2·b1 + … + 2 λ-1 ·b λ-1 ≥ q. Judge the relationship between the high - order segment of λ - l bits q λ-1 , q λ-2 , …, q l+1 , q l and b λ-1 , b λ-2 , …, b l+1 , b l : If q λ-1 = b λ-1 , q λ-2 = b λ-2 , …, q l+1 = b l+1 , q l = b l , then proceed to step Z3.
[0071] Step Z3: If k > 0, judge the relationship between the low - order k bits q k-1 , q k-2 , …, q0 and b k-1 , b k-2 , …, b0: If q k-1 = b k-1 , q k-2 = b k-2 , …, q0 = b0, then from the l - k bits b k , b k+1 , …, b l-1 Select some or all of them for recycling and count them as available bits for use in step B2 of the sampling algorithm.
[0072] In this embodiment, for the positive integer m in the sample space and a sampling 0 ≤ s < m, the above method may further include the following steps:
[0073] Step E1: Set the sampling space to have at least ν bits of complete information. That is
[0074] Step E2: According to the binary representation of the non - negative integer s where s0, s1, …, s ν-1 , s v ∈ {0, 1}, if s < 2 v , then extract some or all of the bits from the lower v bits e0, e1, …, e ν-1 of the non - negative integer s for recycling and count them as available bits for use in step B2 of the sampling algorithm. If s ≥ 2 v , the current recycling fails. Proceed to step B2.
[0075] In this embodiment, step B3 above may further include the following steps:
[0076] Step F1: Given that λ bits b0, b1, …, b λ-1 are taken from the given bit string to form a non - negative integer s = b0 + 2·b1 + … + 2 λ-1 ·b λ-1 ≥ q. Discard the used b0, b1, …, b λ-1 , but take the complementary space sampling e = s - q caused by the rejection.
[0077] Step F2: For the positive integer 2 λ - q in the sample space and a sampling e, run steps E1 and E2.
[0078] In this embodiment, step F2 above may further include the following steps:
[0079] Step G1: For the positive integer 2 λ - q in the sample space and a sampling e, run step E1, and then run step E2. If the current recycling fails when running step E2, then for the positive integer in the sample space and a sampling run steps E1 and E2.
[0080] Step G2: If the current recycling fails when running step E2, it can return to step B2, or it can continue to recycle available bits using the methods of steps E1 and E2 as needed.
[0081] In this embodiment, bitwise operations such as bitwise AND, OR, NOT, XOR, or other equivalent operations may be used in the above operations.
[0082] It should be emphasized that rejection sampling is a key method in post-quantum cryptography, requiring significant computational resources. This paper proposes a rejection sampling technique with recycling for limited-space rejection sampling, particularly uniformly distributed sampling over a modulo-non-power-of-2 integer remainder ring. Through simple and rapid detection and judgment, this technique recycles the (pseudo)random bits still available during rejection operations for subsequent sampling. This reduces the total number of (pseudo)random bits used, shortens the computational time of the pseudo-random generation mechanism, and ultimately reduces the overall runtime of post-quantum cryptography algorithms.
[0083] Compared with the previously existing methods, the present invention has the following new features and benefits:
[0084] 1) Recover usable (pseudo) random bits in rejected samples, and the recovered bits are independently random and have no impact on security;
[0085] 2) Reduce the overall sampling time consumption of the algorithm, especially for integers whose moduli are friendly to Number Theory Transform (NTT).
[0086] A second embodiment of the present invention is an electronic device, such as Figure 2 As shown, it can be understood as a physical device, including a processor and a memory storing processor-executable instructions. When the instructions are executed by the processor, the following operations are performed:
[0087] Step A1: inputting a bit string of sufficient length, wherein the bit string is a random bit string or a pseudo-random bit string;
[0088] Step A2: If the bit string of the preset length meets the target distribution requirement, then accept a sample of the processed output, discard the used bit string, and proceed to step A4; if the bit string of the preset length does not meet the target distribution requirement, then proceed to step A3;
[0089] Step A3: extracting independent and uniformly distributed bit strings from the bit string of the preset length used in Step A2, recycling them as input to Step A2 or as part of the input, discarding the unextracted bit strings, and proceeding to Step A2;
[0090] Step A4: If the number of output samples does not meet the requirement, go to step A2; if the number of output samples meets the requirement, end.
[0091] In the third embodiment of the present invention, the process of the rejection sampling method with recovery in this embodiment is the same as that in the first and second embodiments, except that, in terms of engineering implementation, this embodiment can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the method of the present invention can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions for enabling a device to execute the method described in the embodiment of the present invention.
[0092] The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art will readily appreciate that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention shall be included within the scope of protection of the present invention.
Claims
1. A rejection sampling method with recovery, characterized in that include: Step A1: inputting a bit string of sufficient length, wherein the bit string is a random bit string or a pseudo-random bit string; Step A2: If the bit string of the preset length meets the conditions of the target distribution requirement, then accept a sample of the processed output, discard the used bit string, and enter step A4; if the bit string of the preset length does not meet the conditions of the target distribution requirement, then proceed to step A3; Step A3: extracting independent and uniformly distributed bit strings from the bit string of the preset length used in step A2, recycling them as input of step A2 or as part of the input, discarding the bit strings that have not been extracted, and entering step A2; Step A4: If the number of output samples does not meet the requirement, go to step A2; if the number of output samples meets the requirement, end.
2. The rejection sampling method with recovery according to claim 1, characterized in that: represents the remainder class ring of positive integers modulo q, in which element addition and multiplication are performed modulo q, for The method comprises: Step B2: Take λ bits b0, b1, …, b from the given bit string λ-1 to form a non - negative integer If b < q, then output b as a sample uniformly distributed on, discard the used b0, b1, …, b λ-1 , and enter Step B4; if the determination condition is not satisfied, enter Step B3; Step B3, extracting independent and uniformly distributed bit strings from the bit strings used in step B2, recycling and counting them into available bits for use in step B2, and entering step B2; Step B4: If the number of output samples does not meet the requirement, go to step B2; if the number of output samples meets the requirement, end.
3. The rejection sampling method with recovery according to claim 2, characterized in that: The step B3 comprises: Step C1: Take λ bits b0, b1, ..., b from the given bit string λ-1 Form a non-negative integer b = b0 + 2 b1 + ... + 2 λ-1 b λ-1 ≥q, take a high-order segment of η bits b λ-1 , b λ-2 , ..., b λ-η , where 1<η<λ and q λ-1 ,q λ-2 , ..., q λ-η Not all are 1; Step C2: Determine n bits b λ-1 , b λ-2 , ..., b λ-η The integer composed of With integers If c>d, from λ-η bits b0, b1, ..., b λ-η-1 Select part or all of them to be recovered and counted into the available bits for use in step B2 of the sampling algorithm, and enter step B2.
4. The rejection sampling method with recovery according to claim 2, characterized in that: The step B3 comprises: Step D1: Take λ bits b0, b1, ..., b from the given bit string λ-1 Form a non-negative integer s = b0 + 2 b1 + ... + 2 λ-1 b λ-1 ≥q, take a high-order segment of η bits b λ-1 , b λ-2 , ..., b λ-η , where 1<η<λ and q λ-1 ,q λ-2 , ..., q λ-η Not all are 1; Step D2: Target Determine a set L, the elements of which consist of one or more integers greater than d, and determine n bits b λ-1 , b λ-2 , ..., b λ-η The integer composed of Relationship with set L; if c belongs to set L, from λ-η bits b0, b1, ..., b λ-η-1 Select part or all of them to be recovered and counted into the available bits for use in step B2 of the sampling algorithm, and enter step B2.
5. The rejection sampling method with recovery according to claim 2, characterized in that: The step B3 comprises: Step Z1: Find an integer kl that satisfies 0≤k<l<λ, such that q k ,q k+1 , ..., q l-1 All equal to 0; Step Z2: Take λ bits b0, b1, ..., b in the given bit string λ-1 Form a non-negative integer s = b0 + 2 b1 + ... + 2 λ-1 b λ-1 ≥q, determine the high-order segment of λ-l bits q λ-1 ,q λ-2 , ..., q l+1 ,q l With b λ-1 , b λ-2 , ..., b l+1 , b l Relationship: If q is satisfied λ-1 = bλ -1 ,q λ-2 =b λ-2 ,...,q l+1 =b l+1 ,q l =b l , proceed to step Z3; Step Z3: If k>0, determine the lower k bits q k-1 ,q k-2 , ..., q0 and b k-1 , b k-2 , ..., b0: If q k-1 =b k-1 ,q k-2 =b k-2 , ..., q0 = b0, from lk bits b k , b k+1 , ..., b l-1 Some or all of the bits are selected and recovered and counted into the available bits for use in step B2 of the sampling algorithm.
6. The rejection sampling method with recovery according to claim 2, characterized in that: If there is a sample space positive integer m and a sampling 0≤s<m, the method includes: Step E1: Set the sampling space to have at least v bits of complete information, i.e. Step E2: Based on the binary representation of the non-negative integer s where s0, s1, ..., s ν-1 ,s ν ∈{0, 1}, if s<2 v , from the low-order v bits e0, e1, ..., e of the non-negative integer s ν-1 Extract some or all of the recovered bits and count them into the available bits for use in step B2 of the sampling algorithm if s ≥ 2 v , then the current recycling fails and goes to step B2.
7. The rejection sampling method with recovery according to claim 6, characterized in that: The step B3 comprises: Step F1: Take λ bits b0, b1, ..., b from the given bit string λ-1 Form a non-negative integer s = b0 + 2 b1 + ... + 2 λ-1 b λ-1 ≥q, discard the used b0, b1, ..., b λ-1 , take the complementary space sampling e=sq caused by rejection; Step F2: For the sample space positive integer 2 λ -q and a sample e, run steps E1 and E2.
8. The rejection sampling method with recovery according to claim 7, characterized in that: The step F2 comprises: Step G1: For the sample space positive integer 2 λ -q and a sample e, run step E1, step E2; if the current recovery fails when running step E2, then for the sample space positive integer and a sample Run step E1 and step E2; Step G2: If the current recycling fails when running step E2, return to step B2, or use the methods of steps E1 and E2 to recycle bits.
9. An electronic device, characterized in that: The electronic device comprises: a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the rejection sampling method with recovery as claimed in any one of claims 1 to 8 when executed by the processor.
10. A computer storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the rejection sampling method with recovery as claimed in any one of claims 1 to 8.
