({{, (RefLink[RandomPrime, paclet:ref/RandomPrime])[{(Subscript[i, min]),(Subscript[i, max])}] 
gives a pseudorandom prime number in the range (Subscript[i, min]) to (Subscript[i, max]).}, {, (RefLink[RandomPrime, paclet:ref/RandomPrime])[(Subscript[i, max])] 
gives a pseudorandom prime number in the range 2 to (Subscript[i, max]).}, {, (RefLink[RandomPrime, paclet:ref/RandomPrime])[range,n] 
gives a list of n pseudorandom primes.}})

OpenersNotesSection(Spacer1)Details

A random prime p 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.

(RefLink[RandomPrime, paclet:ref/RandomPrime])[{(Subscript[i, min]),(Subscript[i, max])}] chooses primes between (Subscript[i, min]) and (Subscript[i, max]) with equal probability.

(RefLink[RandomPrime, paclet:ref/RandomPrime])[(Subscript[i, max])] is equivalent to (RefLink[RandomPrime, paclet:ref/RandomPrime])[{2,(Subscript[i, max])}].

(RefLink[RandomPrime, paclet:ref/RandomPrime])[range,{(Subscript[n, 1]),(Subscript[n, 2]),…}] gives an (Subscript[n, 1])×(Subscript[n, 2])×… array of primes.

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

A random prime less than 100:

RandomPrime[100]

A random 10-digit prime:

RandomPrime[{(10^9),(10^10)}]

A list of 10 pseudorandom primes less than 100:

RandomPrime[100,10]

OpenersExampleSection1(Spacer1)Scope  (1)

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

RandomPrime[10,{4,5}]

OpenersExampleSection3(Spacer1)Applications  (1)

Find two large primes for use in RSA encryption:

{p,q}=RandomPrime[{2^639,2^640},2]

This is a 640-binary-digit number:

Total[DigitCount[p,2]]

IntegerLength[p,2]

Its binary representation:

BaseForm[p,2]

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

Sampling of primes from 1 to 100:

data=RandomPrime[{1,100},10^4];

The distribution is uniform over the primes:

ListPlot[Tally[data],Filling  -> Axis, PlotRange->All,AxesOrigin->{0,0}]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

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

RandomPrime[{14,16}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NextPrime, paclet:ref/NextPrime])  ▪  (RefLink[RandomInteger, paclet:ref/RandomInteger])  ▪  (RefLink[PrimeQ, paclet:ref/PrimeQ])  ▪  (RefLink[GenerateAsymmetricKeyPair, paclet:ref/GenerateAsymmetricKeyPair])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Integer and Number Theoretic Functions, paclet:tutorial/IntegerAndNumberTheoreticalFunctions])}, {▪(RefLinkPlain[Random Number Generation, paclet:tutorial/RandomNumberGenerationOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Cryptographic Number Theory, paclet:guide/CryptographicNumberTheory])}, {▪(RefLinkPlain[Random Number Generation, paclet:guide/RandomNumberGeneration])}, {▪(RefLinkPlain[Prime Numbers, paclet:guide/PrimeNumbers])}, {▪(RefLinkPlain[Mathematical Functions, paclet:guide/MathematicalFunctions])}})}})