Home | Develop | Download | Contact
testpdsrv2.c
1 /*
2  * testpdsrv2.c
3  *
4  * Copyright 2011 Fernando Pujaico Rivera <fernando.pujaico.rivera@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  *
21  */
22 
35 #include <config.h>
36 #include <stdlib.h>
37 #include <pds/pdsrv.h>
38 
39 
40 int main(int argc, char** argv)
41 {
42  unsigned long i;
43  PdsUniform *X1=NULL;
44  PdsGaussian *X2=NULL;
45  PdsRayleigh *X3=NULL;
46  PdsRvReal x1;
47  PdsRvReal x2;
48  PdsRvReal x3;
49 
50  X1=pds_uniform_new(0.0,1.0);
51  printf("Uniform(0.0,1.0): No debe contener 1.0: Debe contener 0.0\n");
52  for(i=0;i<=(PDS_RAND_MAX+1);i++)
53  {
54  pds_uniform_get_value(X1,&x1);
55  if(x1==0.0) printf("Encontrado 0.0\n");
56  if(x1==1.0) printf("Encontrado 1.0:%11.9e:%10lu:%10lu\n",x1,PDS_RAND_MAX,X1->X1->x0);
57 
58  if(i%(PDS_RAND_MAX/100)==0) printf("%2d%c\n",(int)(i*100.0/PDS_RAND_MAX),'%');
59  }
60  pds_uniform_free(X1);
61  printf("\n");
62 
63 
64  X2=pds_gaussian_new(0.0,1.0);
65  printf("Gauss(0.0,1.0):No debe contener infinitos: Debe contener 0.0\n");
66  for(i=0;i<=(PDS_RAND_MAX+1);i++)
67  {
68  pds_gaussian_get_value(X2,&x2);
69  if(X2->X1->x0<4UL) printf("Encontrado cero:%11.9e\t[x0=%10lu/%10lu]\n",x2,X2->X1->x0,PDS_RAND_MAX);
70  if(X2->X1->x0>(PDS_RAND_MAX-4UL)) printf("Encontrado Máximo:%11.9e\t[x0=%10lu/%10lu]\n",x2,X2->X1->x0,PDS_RAND_MAX);
71 
72  if(i%(PDS_RAND_MAX/100)==0) printf("%2d%c\n",(int)(i*100.0/PDS_RAND_MAX),'%');
73  }
75  printf("\n");
76 
77 
78  X3=pds_rayleigh_new(1.0);
79  printf("Rayleigh(1.0):No debe contener infinitos: Debe contener 0.0\n");
80  for(i=0;i<=(PDS_RAND_MAX+1);i++)
81  {
82  pds_rayleigh_get_value(X3,&x3);
83  if(X3->X1->x0<4UL) printf("Encontrado cero:%11.9e\t[x0=%10lu/%10lu]\n",x3,X3->X1->x0,PDS_RAND_MAX);
84  if(X3->X1->x0>(PDS_RAND_MAX-4UL)) printf("Encontrado Máximo:%11.9e\t[x0=%10lu/%10lu]\n",x3,X3->X1->x0,PDS_RAND_MAX);
85 
86  if(i%(PDS_RAND_MAX/100)==0) printf("%2d%c\n",(int)(i*100.0/PDS_RAND_MAX),'%');
87  }
89  printf("\n");
90 
91 
92 
93  return EXIT_SUCCESS;
94 }
95 
96 
PdsCongruential * X1
Definition: pdsuniform.h:74
int pds_gaussian_get_value(PdsGaussian *X, PdsRvReal *x)
Retorna un número pseudo aleatorio gaussiano, N(U,Sigma^2) .
PdsRayleigh * pds_rayleigh_new(PdsRvReal Sigma)
Crea una variable aleatoria de tipo PdsRayleigh.
#define PDS_RAND_MAX
PdsUniform * pds_uniform_new(PdsRvReal A, PdsRvReal B)
Crea una variable aleatoria de tipo PdsUniform.
float PdsRvReal
Definition: pdsrvglobal.h:59
PdsCongruential * X1
Definition: pdsgaussian.h:67
PdsGaussian * pds_gaussian_new(PdsRvReal U, PdsRvReal Sigma)
Crea una variable aleatoria de tipo PdsGaussian.
void pds_gaussian_free(PdsGaussian *X)
Libera la variable aleatoria de tipo puntero PdsGaussian.
int pds_rayleigh_get_value(PdsRayleigh *X, PdsRvReal *x)
Retorna un número pseudo aleatorio rayleighiano, Rayleighiana(Sigma) .
La estructura tipo PdsUniform. Esta estructura genera una variable aleatoria uniformemente distribuid...
Definition: pdsuniform.h:69
PdsCongruential * X1
Definition: pdsrayleigh.h:67
void pds_uniform_free(PdsUniform *X)
Libera la variable aleatoria de tipo puntero PdsUniform.
La estructura tipo PdsGaussian. Esta estructura genera una variable aleatoria gaussiana normalizada...
Definition: pdsgaussian.h:64
PdsRvNaturalD x0
void pds_rayleigh_free(PdsRayleigh *X)
Libera la variable aleatoria de tipo puntero PdsRayleigh.
La estructura tipo PdsRayleigh. Esta estructura genera una variable aleatoria rayleighiana, Rayleighiana(Sigma) . Para usar incluir pdsrv/pdsrv.h. La función de densidad de probabilidad es: fx(x)=(x/Sigma^2)e^{-x^2/(2 Sigma^2)} x>=0 .
Definition: pdsrayleigh.h:64
int pds_uniform_get_value(PdsUniform *X, PdsRvReal *x)
Retorna un número pseudo aleatorio y uniforme entre [A,B), con PDS_RAND_MAX divisiones de resolución...

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed