Home | Develop | Download | Contact
example_coin.c
1 /*
2  * example_coin.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 
23 
24 
39 /* gcc -o example_coin example_coin.c -lpdsrv */
40 #include <stdio.h>
41 #include <pds/pdsrv.h>
42 
43 int main(int argc, char** argv)
44 {
45  PdsCoin *Coin=NULL;
46  PdsRvReal x;
47  int i;
48 
49  /* Creando una moneda con Pr(Coin=1)=0.5 */
50  Coin=pds_coin_new(0.5);
51 
52  for(i=0;i<16;i++)
53  {
54  /* Obteniendo el resultado de lanzar una moneda */
55  pds_coin_get_value(Coin, &x);
56 
57  /* Mostrando el resultado por pantalla */
58  printf("Coin:\t%f\n",x);
59  }
60 
61  return EXIT_SUCCESS;
62 }
La estructura tipo PdsCoin. Esta estructura genera una variable aleatoria de Bernoulli. Para usar, incluir pdsrv/pdsrv.h. La función de densidad de probabilidad es: fx(x=1)=p, fx(x=0)=1-p, fx(x=other)=0 .
Definition: pdscoin.h:65
int pds_coin_get_value(PdsCoin *X, PdsRvReal *x)
Pide un valor {-1,1} a la variable aleatoria de tipo PdsCoin.
float PdsRvReal
Definition: pdsrvglobal.h:59
PdsCoin * pds_coin_new(PdsRvReal p)
Crea una variable aleatoria de tipo PdsCoin.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed