RandomPrime

RandomPrime[{imin,imax}]

gives a pseudorandom prime number in the range imin to imax.

RandomPrime[imax]

gives a pseudorandom prime number in the range 2 to imax.

RandomPrime[range,n]

gives a list of n pseudorandom primes.

Details

  • A random prime is computed by repeatedly generating pseudorandom integers in the specified range until the desired number of primes has been produced.
  • If no prime exists in the specified range, the input is returned unevaluated with an error message.
  • RandomPrime[{imin,imax}] chooses primes between imin and imax with equal probability.
  • RandomPrime[imax] is equivalent to RandomPrime[{2,imax}].
  • RandomPrime[range,{n1,n2,}] gives an n1×n2× array of primes.

Examples

open allclose all

Basic Examples  (3)

A random prime less than 100:

In[1]:=
Click for copyable input
Out[1]=

A random 10-digit prime:

In[1]:=
Click for copyable input
Out[1]=

A list of 10 pseudorandom primes less than 100:

In[1]:=
Click for copyable input
Out[1]=

Scope  (1)

Applications  (1)

Properties & Relations  (1)

Possible Issues  (1)

See Also

NextPrime  RandomInteger  PrimeQ  GenerateAsymmetricKeyPair

Tutorials

Introduced in 2007
(6.0)