openGPMP
Open Source Mathematics Package
primes2.cpp
Go to the documentation of this file.
1 #include <chrono>
2 #include <cmath>
3 #include <iostream>
5 #include <random>
6 #include <vector>
7 
8 int main() {
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
int main()
Definition: primes2.cpp:8