Function Repository Resource:

# RandomSafePrime

Compute one or more safe primes in a requested range

Contributed by: Arnoud Buzing
 ResourceFunction["RandomSafePrime"][max] gives a safe prime equal or less than max. ResourceFunction["RandomSafePrime"][{min,max}] gives a safe prime in the range min to max. ResourceFunction["RandomSafePrime"][range,n] gives n safe primes in the specified range.

## Details and Options

A safe prime is a prime number of the form 2p+1, where p is also a prime.
ResourceFunction["RandomSafePrime"] uses RandomPrime to generate candidate safe primes. Generating the requested number of safe primes may take a significant amount of time. Ranges that contain no safe primes will eventually time out.
ResourceFunction["RandomSafePrime"] will time out after 60 seconds. This time-out can be modfied with the TimeConstraint option.

## Examples

### Basic Examples (2)

Generate a random safe prime:

 In[1]:=
 Out[1]=

Check that it is indeed a safe prime using the resource function SafePrimeQ:

 In[2]:=
 Out[2]=

Generate several safe primes:

 In[3]:=
 Out[3]=

Check that they are safe primes via the resource function SafePrimeQ:

 In[4]:=
 Out[4]=

### Scope (2)

Generate a safe prime in a specific range:

 In[5]:=
 Out[5]=

Generate several safe primes in a specific range:

 In[6]:=
 Out[6]=

### Options (1)

Attempting to generate a large number of safe primes in a small amount of time will time out:

 In[7]:=
 Out[7]=

Arnoud Buzing

## Version History

• 1.0.0 – 08 May 2020