-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unbiased random prime generation #23
Comments
Some investigation results of the algorithm from the paper above (Fig. 2). The steps 1-7 (finding So it doesn't seem like we can just replace the existing sieve, but the method does have value when an unbiased generation is required. Notes:
|
I can note my explicit interest in this for use in a hash-to-prime function. I'd also be curious to benchmark it when it's not using a distinctly sampled random numbers, yet only generating a single new byte/chunk and shifting over the generated bits (questioning how much of the cost is due to generating KB-MB of random numbers). |
I didn't measure it, but it feels like the contribution of RNG is quite minimal. |
I think we are safe from this, at least as far as the Our sieve starts with a random odd integer In our case however, we exit the loop once a prime is found and discard the For use cases where the |
A way to get an unbiased sampling of safe primes given an unbiased sampling of regular primes: https://www.degruyter.com/document/doi/10.1515/jmc-2013-5011/pdf. |
Currently random prime generation starts from a random number and runs a sieve until a prime is found. This can introduce bias, selecting primes with large leads more often. Some assorted considerations:
a < 2^(k-1)
, and generate candidates as2^(k-1) + (a + i * b mod 2^(k-1))
whereb
is a random odd number. This will uniformly cover all the range[2^(k-1), 2^k)
(right?) May be a little faster but not too much.The text was updated successfully, but these errors were encountered: