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:

A random 10-digit prime:

A list of 10 pseudorandom primes less than 100:

Scope  (1)

Generate a random array of primes less than 11 of dimension 4×5:

Applications  (1)

Find two large primes for use in RSA encryption:

This is a 640-binary-digit number:

Its binary representation:

Properties & Relations  (1)

Sampling of primes from 1 to 100:

The distribution is uniform over the primes:

Possible Issues  (1)

If no prime exists in the specified range, an error message is returned:

Wolfram Research (2007), RandomPrime, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomPrime.html.

Text

Wolfram Research (2007), RandomPrime, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomPrime.html.

CMS

Wolfram Language. 2007. "RandomPrime." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RandomPrime.html.

APA

Wolfram Language. (2007). RandomPrime. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomPrime.html

BibTeX

@misc{reference.wolfram_2023_randomprime, author="Wolfram Research", title="{RandomPrime}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/RandomPrime.html}", note=[Accessed: 18-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_randomprime, organization={Wolfram Research}, title={RandomPrime}, year={2007}, url={https://reference.wolfram.com/language/ref/RandomPrime.html}, note=[Accessed: 18-March-2024 ]}