Skip to content
Snippets Groups Projects
Commit 46a25dab authored by Armando Luiz Nicolini Delgado's avatar Armando Luiz Nicolini Delgado :nerd:
Browse files

/* Adicionados algumas alternativas de funções, mas ainda comentadas */

parent ca72d61e
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Gerador de números pseudo-aleatórios // Gerador de números pseudo-aleatórios
// Período do gerador: 3.138e57 (aprox.) // 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 { static struct Ran {
Ullong u,v,w; Ullong u,v,w;
...@@ -35,12 +35,25 @@ Ullong nrRandom64() ...@@ -35,12 +35,25 @@ Ullong nrRandom64()
return (x + randomNR.v) ^ randomNR.w; 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(); } Doub nrDrandom() { return 5.42101086242752217E-20 * nrRandom64(); }
// Retorna int-32 bits entre 0 e 2³² - 1 // Retorna int-32 bits entre 0 e 2³² - 1
Uint nrRandom32() { return (Uint) nrRandom64(); } 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 { struct Ranq1 {
Ullong v; Ullong v;
......
...@@ -40,7 +40,7 @@ typedef unsigned char Bool; ...@@ -40,7 +40,7 @@ typedef unsigned char Bool;
// Functions // Functions
// Período do gerador: 3.138e57 (aprox.) // 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 // Define a semente
void nrSeed(Ullong j); void nrSeed(Ullong j);
...@@ -51,4 +51,11 @@ Doub nrDrandom(); ...@@ -51,4 +51,11 @@ Doub nrDrandom();
// Retorna int-32 bits entre 0 e 2³² - 1 // Retorna int-32 bits entre 0 e 2³² - 1
Uint nrRandom32(); Uint nrRandom32();
/*
// Tipos de geradores
typedef enum {UNIX, UNIX48, NR} Randtype;
// Define o tipo de gerador
void setRandGen(Randtype t);
*/
#endif /* _RANDOMNR_H_ */ #endif /* _RANDOMNR_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment