openGPMP
Open Source Mathematics Package
Functions
primes2.cpp File Reference
#include <chrono>
#include <cmath>
#include <iostream>
#include <openGPMP/nt/prime_gen.hpp>
#include <random>
#include <vector>

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( void  )

Definition at line 8 of file primes2.cpp.

8  {
9  std::random_device rd;
10  std::mt19937 gen(rd());
11  int max_number = 50000;
12 
13  auto start = std::chrono::high_resolution_clock::now();
14 
15  std::vector<int> primes =
17 
18  auto end = std::chrono::high_resolution_clock::now();
19  std::chrono::duration<double> duration = end - start;
20 
21  std::cout << "Prime numbers generated: " << primes.size() << std::endl;
22  std::cout << "Time taken: " << duration.count() << " seconds" << std::endl;
23 
24  // Generate a random prime number from the list
25  if (!primes.empty()) {
26  std::uniform_int_distribution<> distrib(0, primes.size() - 1);
27  int random_index = distrib(gen);
28  std::cout << "Random prime number: " << primes[random_index]
29  << std::endl;
30  } else {
31  std::cout << "No prime numbers generated." << std::endl;
32  }
33 
34  return 0;
35 }
static std::vector< int > sieve_of_eratosthenes(int n)
Definition: prime_gen.cpp:49

References gpmp::PrimalityGen::sieve_of_eratosthenes().