#!/bin/bash
echo "Enter the number of prime numbers to generate:"
read count
# Loop to generate the specified number of prime numbers
for i in $(seq 1 $count);
do
openssl prime -generate -bits 2048 >> primes.txt
done
echo "Prime numbers generated and saved in primes.txt"
This script prompts the user to enter the number of prime numbers to generate, and then uses a loop to generate that number of prime numbers using the openssl prime -generate -bits 2048
command. The -bits 2048
flag specifies that the generated primes should be 2048 bits in length and the result is saved in a file called ‘primes.txt’.
Please note that OpenSSL’s prime
command uses a strong random number generator and it is suitable for generating primes of a wide range of lengths but it may take a long time to generate very large prime numbers, depending on the system’s resources and the number of primes to generate.