CluE  1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
primegenerator.h
Go to the documentation of this file.
1 #ifndef PRIMEGENERATOR_H
2 #define PRIMEGENERATOR_H
3 
4 #include <random>
5 #include <ctime>
6 
7 #include "../misc/randomness.h"
8 
9 namespace CluE
10 {
11 
16 {
17 //TODO Overflow check
18 //TODO Exceptions
19 //NOTE Performance tweaks to consider
20 // - More efficient sampling method
21 
22 public:
26  unsigned long long getPrime(unsigned long long lowerBound, unsigned long long upperBound, double errorProbability);
27 
31  bool isMillerRabinPrime(unsigned long long candidate, double errorProbability);
32 
33 private:
39  unsigned long long potMod(unsigned long long x, unsigned long long b, unsigned long long m);
40 };
41 
42 }
43 
44 #endif
bool isMillerRabinPrime(unsigned long long candidate, double errorProbability)
Miller-Rabin primality test.
unsigned long long potMod(unsigned long long x, unsigned long long b, unsigned long long m)
Calculates "x^b mod m".
unsigned long long getPrime(unsigned long long lowerBound, unsigned long long upperBound, double errorProbability)
Returns a number [lowerBound, upperBound] which is prime with probablity 1-errorProbability.
Generates numbers which are (most likely) prime numbers.