# Revision history [back]

You can use a rejection method: try a new random prime until you get a safe one:

sage: def rdp(nbits=512):
....:     while True:
....:         p = random_prime(2^nbits-1, false, 2^(nbits-1))
....:         if ZZ((p+1)/2).is_prime():
....:             return p
....:
sage: rdp()
9075892275451579482861175762932106084253268411540277039314929550059578374557168263115660009649748089090540343402740578371326513035684052420493647284687893


For other number of bits:

sage: rdp(200)
1011992113066581800000651861935373321407012277464235251049677


You can use a rejection method: try a new random prime until you get a safe one:

sage: def rdp(nbits=512):
....:     while True:
....:         p = random_prime(2^nbits-1, false, 2^(nbits-1))
....:         if ZZ((p+1)/2).is_prime():
ZZ((p-1)/2).is_prime():
....:             return p
....:
sage: rdp()
9075892275451579482861175762932106084253268411540277039314929550059578374557168263115660009649748089090540343402740578371326513035684052420493647284687893


For other number of bits:

sage: rdp(200)
1011992113066581800000651861935373321407012277464235251049677