/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <time.h>
#include <random>
int isPrimeNumber (int num)
{
if (num == 1) return 0;
for (int i = 2; i <= sqrt (num); i++)
{
if (num % i == 0)
{
// not prime
return 0;
}
}
// prime
return 1;
}
int main ()
{
std::random_device rd;
std::mt19937 rng (rd ());
// Define prime range from 2 to 2^31 - 1.
std::uniform_int_distribution < int >uni (2, 2147483647);
int prime;
// Generate a random prime.
do { prime = uni (rng); } while (!isPrimeNumber(prime));
printf ("prime = %d", prime);
return 0;
}