How do I quickly generate a random prime number, that is for sure 1024 bit long?
相关问题
- Finding k smallest elements in a min heap - worst-
- binary search tree path list
- High cost encryption but less cost decryption
- Unity - Get Random Color at Spawning
- How do I merge consecutive numbers in a sorted lis
相关文章
- What are the problems associated to Best First Sea
- Coin change DP solution to keep track of coins
- why 48 bit seed in util Random class?
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Algorithm for maximizing coverage of rectangular a
- Need help generating discrete random numbers from
- How to measure complexity of a string?
You do not specify a context/language/platform.. if you'd like to use unix/linux-like system and shell, you might consider a solution involving OpenSSL version >= 1.0.0:
If you got the same result, something is very wrong with the universe.
Add
-hex
option if you like hexadecimal system.In PARI/GP:
If you'd like to do this in 'library mode'
1024 is a lot. Are you sure a probabilistic prime won't do? Probabilistic prime generator is part of JDK
To trade memory for speed you could just generate them and store them in a list and then randomly pick one.
Edit: Naturally you can't generate them all so the best you could achieve is pseudo randomness at a high memory cost. Also this isn't good if you want it for security.
Generate 1024 random bits. Use a random source that is strong enough for your intended purpose.
Set the highest and lowest bits to 1. This makes sure there are no leading zeros (the prime candidate is big enough) and it is not an even number (definitely not prime).
Test for primality. If it's not a prime, go back to 1.
Alternatively, use a library function that generates primes for you.
Use a library function, such as OpenSSL. There's no need to write this yourself.
Example: http://ardoino.com/7-maths-openssl-primes-random/