title: How to get a prime of a given length in Sage?
body: <p>How can I get a random prime of a given bit length in Sage? </p>
  
  <p>For example, to get a 512-bit prime, I tried</p>
  
  <pre><code>p = random_prime(2^512)
  </code></pre>
  
  <p>but according to the documentation:</p>
  
  <blockquote>
    <p>The command random_prime(a, True) will return a random prime between 2 and a</p>
  </blockquote>
  
  <p>so I can't use it, since I need a prime of an exact length.</p>