From 46a25dabdfe7bcb8ef7a9330b5c5ccc79534d7fa Mon Sep 17 00:00:00 2001 From: Armando Luiz Nicolini Delgado <nicolui@inf.ufpr.br> Date: Wed, 8 Nov 2023 09:35:51 -0300 Subject: [PATCH] =?UTF-8?q?/*=20Adicionados=20algumas=20alternativas=20de?= =?UTF-8?q?=20fun=C3=A7=C3=B5es,=20mas=20ainda=20comentadas=20*/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/randomNR.c | 17 +++++++++++++++-- utils/randomNR.h | 9 ++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/utils/randomNR.c b/utils/randomNR.c index 7719e4a..0ea3bd3 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 89b1f66..69e36bb 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_ */ -- GitLab