OpenSSL::BN::generate_prime(500) will do this as abdollar said. Be sure to place require 'openssl' at the top to include it in your ruby ββfile
To check the correct number of bits, you can print the binary just by running OpenSSL::BN::generate_prime(500).to_i.to_s(2).length and it will output 500 and the most significant bit will be 1
Open SSL documentation
source share