00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #if !defined TRNGLIB_H
00022
00023 #define TRNGLIB_H
00024
00025 #include <vector>
00026 #include <exception>
00027 #include <string>
00028
00029 namespace TRNG {
00030
00032
00036 class error : public std::exception {
00037 std::string _what;
00038 public:
00039 virtual const char * what(void) const throw() {
00040 return _what.c_str();
00041 };
00042 explicit error(const std::string &what_arg) : _what(what_arg) {
00043 };
00044 virtual ~error() throw() {
00045 };
00046
00047 };
00048
00050
00055 class power {
00056 long b, modulus;
00057 unsigned long b_power0[0x10000];
00058 unsigned long b_power1[0x08000];
00059
00060 long pow(long n) {
00061 long long p=1ll, t=b;
00062 while (n>0) {
00063 if ((n&0x1)==0x1)
00064 p=(p*t)%modulus;
00065 t=(t*t)%modulus;
00066 n/=2;
00067 }
00068 return static_cast<long>(p);
00069 }
00070
00071 void calc_b_power(void) {
00072 for (long i=0l; i<0x10000l; ++i)
00073 b_power0[i]=pow(i);
00074 for (long i=0l; i<0x08000l; ++i)
00075 b_power1[i]=pow(i*0x10000l);
00076 }
00077
00078 public:
00079 long operator()(const long n) const {
00080 if (modulus==2147483647l) {
00081 unsigned long long z=
00082 static_cast<unsigned long long>(b_power1[n>>16])*
00083 static_cast<unsigned long long>(b_power0[n&0xffff]);
00084 z=(z&0x7fffffffull)+(z>>31);
00085 return (z>=modulus) ? (z-modulus) : z;
00086 } else
00087 return static_cast<long int>((static_cast<unsigned long long>(b_power1[n>>16])*
00088 static_cast<unsigned long long>(b_power0[n&0xffff]))
00089 %modulus);
00090 }
00091
00092 long operator()(void) const {
00093 return b;
00094 }
00095
00096 void set(const long b_, const long modulus_) {
00097 b=b_;
00098 modulus=modulus_;
00099 calc_b_power();
00100 }
00101
00102 power(const long b_, const long modulus_) :
00103 b(b_),
00104 modulus(modulus_) {
00105 calc_b_power();
00106 }
00107
00108 virtual ~power() {
00109 }
00110 };
00111
00112 const char * version(void);
00113 long modulo_invers(long, long);
00114 void gauss(std::vector<long> &, std::vector<long> &, long);
00115 void matrix_mult(const std::vector<long> &, const std::vector<long> &,
00116 std::vector<long> &, long);
00117 void matrix_vec_mult(const std::vector<long> &, const std::vector<long> &,
00118 std::vector<long> &, long);
00119
00120 double Gamma(double);
00121 double ln_Gamma(double);
00122 double Gamma_P(double, double);
00123 double Gamma_Q(double, double);
00124 double incomp_Gamma(double, double);
00125 double comp_incomp_Gamma(double, double);
00126 double Gamma_ser(double, double);
00127 double Gamma_cf(double, double);
00128 double ln_factorial(long);
00129 long binomial_coeff(long, long);
00130 double errf(double);
00131 double chi_square_test(const std::vector<double> &,
00132 const std::vector<double> &);
00133 double chi_square_prob(double, long);
00134 double Stirling_num2(long, long);
00135 double Student_t(double, long, bool=true);
00136 long find_interval(const std::vector<double> &, double);
00137
00138 double uniform_pdf(double);
00139 double uniform_pdf(double, double, double);
00140 double uniformco_pdf(double);
00141 double uniformco_pdf(double, double, double);
00142 double uniformcc_pdf(double);
00143 double uniformcc_pdf(double, double, double);
00144 double uniformoc_pdf(double);
00145 double uniformoc_pdf(double, double, double);
00146 double uniformoo_pdf(double);
00147 double uniformoo_pdf(double, double, double);
00148 double normal_dist_pdf(double, double, double);
00149 double exp_dist_pdf(double, double);
00150 double laplace_dist_pdf(double, double);
00151 double tent_dist_pdf(double, double);
00152 double Gamma_dist_pdf(double, double, double);
00153 double Beta_dist_pdf(double, double, double);
00154 double chi_square_dist_pdf(double, double);
00155 double Student_t_dist_pdf(double, double);
00156 double binomial_dist_pdf(long, long, double);
00157 double poisson_dist_pdf(long, double);
00158 double geometric_dist_pdf(long, double);
00159
00160 }
00161
00162 #endif
00163
00164