diff --git a/utils/randomNR.c b/utils/randomNR.c index 7719e4a023faf8bc5bfc3ef8161662cdab29e606..0ea3bd30b871229331deda5acf410771591e3a1d 100644 --- a/utils/randomNR.c +++ b/utils/randomNR.c @@ -2,7 +2,7 @@ // Gerador de números pseudo-aleatórios // Período do gerador: 3.138e57 (aprox.) -// Fonte: Press, W.H.; "Numerical Recipes, 3rd ed.", pp.342) +// Fonte: Press, W.H.; "Numerical Recipes, 3rd ed.", Cap. 7, pp.342) static struct Ran { Ullong u,v,w; @@ -35,12 +35,25 @@ Ullong nrRandom64() return (x + randomNR.v) ^ randomNR.w; } -// Retorna int-64 bits entre 0 e 1.0 +// Retorna double-64 bits entre 0 e 1.0 Doub nrDrandom() { return 5.42101086242752217E-20 * nrRandom64(); } // Retorna int-32 bits entre 0 e 2³² - 1 Uint nrRandom32() { return (Uint) nrRandom64(); } +/* +static Ullong (* randFunc) ( void ) = random; +static Doub (* drandFunc) ( void ) = random; +static void (* randSeed) ( Ullong ) = srandom; + +void setRandGen(Randtype t) +{ + if (t == UNIX) { drandFunc = randFunc = random; randSeed = srandom;} + else if (t == UNIX48) { drandFunc = drand48; randFunc = lrand48; randSeed = srand48;} + else if (t == NR) { drandFunc = nrDrandom; randFunc = nrRandom64; randSeed = nrSeed;} +} +*/ + /* struct Ranq1 { Ullong v; diff --git a/utils/randomNR.h b/utils/randomNR.h index 89b1f66b102fe07191fde60b09961d12ae231fc6..69e36bba25627e823d2ad00071981c1676dae641 100644 --- a/utils/randomNR.h +++ b/utils/randomNR.h @@ -40,7 +40,7 @@ typedef unsigned char Bool; // Functions // Período do gerador: 3.138e57 (aprox.) -// Fonte: Press, W.H.; "Numerical Recipes, 3rd ed.", pp.342) +// Fonte: Press, W.H.; "Numerical Recipes, 3rd ed.", Cap. 7, pp.342) // Define a semente void nrSeed(Ullong j); @@ -51,4 +51,11 @@ Doub nrDrandom(); // Retorna int-32 bits entre 0 e 2³² - 1 Uint nrRandom32(); +/* +// Tipos de geradores +typedef enum {UNIX, UNIX48, NR} Randtype; +// Define o tipo de gerador +void setRandGen(Randtype t); +*/ + #endif /* _RANDOMNR_H_ */