RanlibCPP.h

Go to the documentation of this file.
00001 // Contents: Wrapper for ranlib functions
00002 //           
00003 //
00004 // 
00005 //
00006 // Principal Author: Alexei Miasnikov (2002)
00007 //
00008 // Status: in progress
00009 //
00010 
00011 //
00012 //
00013 //   $Id: RanlibCPP.h,v 1.5 2007/09/27 16:44:03 amiasnik Exp $
00014 //
00015 //
00016 
00017 #ifndef _RANLIB_H_
00018 #define _RANLIB_H_
00019 
00020 
00021 #include "ranlib.h"
00022 #include "cdflib.h"
00023 #include <time.h>
00024 #include <unistd.h>
00025 #include <stdlib.h>
00026 #include <iostream>
00027 
00029 
00037 class RandLibURG
00038 {
00039  public:
00041 
00042   RandLibURG(long i1,long i2) {
00043     setall(i1,i2);
00044   }
00045 
00047   RandLibURG() {
00048     setall(time(NULL),time(NULL));
00049     long low = irand(0,2147483560);
00050     long high = irand(0,2147483560);
00051     setall(low,high);
00052   }
00053 
00055   void reset(long i1,long i2) {
00056     setall(i1,i2);
00057   }
00058 
00060   void reset(){
00061     setall(time(NULL),time(NULL));
00062     long low = irand(0,2147483560);
00063     long high = irand(0,2147483560);
00064     setall(low,high); 
00065   }
00066 
00068   void setSeedPID(){
00069     long pid  = getpid();
00070     long low  = labs( (pid + (pid % 131) * time(NULL)) % 2147483560); // pid +  ... is to make shure that 
00071     long high = labs( (pid + (pid % 17)  * time(NULL)) % 2147483560); // that seed will not reduce to 0
00072     setall(low,high); 
00073     low = irand(0,2147483560); 
00074     high = irand(0,2147483560); 
00075     setall(low,high);  
00076   } 
00077 
00079   void getseed( long& s1, long& s2 ){
00080     long iseed1,iseed2;
00081     getsd(&iseed1,&iseed2);
00082     s1 = iseed1; s2 = iseed2;
00083   }
00084 
00086   float rand() {
00087     return ranf(); 
00088   }
00089 
00090   
00092   float rand(float low,float high) {
00093     return genunf( low, high);
00094   }
00095 
00096   
00098   long irand(long low,long high){
00099    return  ignuin( low, high);
00100   }
00101 };
00102 
00103 
00105 class RandLib
00106 {
00107  public:
00109 
00110   static RandLibURG ur;
00111 
00112   
00114   static double chiPValue( int idf, double alpha ){
00115     int which = 2;
00116     double p = 1.0 - alpha;
00117     double q = alpha;
00118     double x;
00119     double df = idf;
00120     int status;
00121     double bound;
00122    
00123     cdfchi(&which,&p,&q,&x,&df,&status,&bound);
00124 
00125     return x;
00126   }
00127 
00128 };
00129 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Mon Sep 26 18:43:45 2011 for CRyptography And Groups (CRAG) by  doxygen 1.6.1