Statistiques
| Révision :

root / Pi / C / SWIG / MCmodule.c @ 184

Historique | Voir | Annoter | Télécharger (804 octet)

1
#include <Python.h>
2
#include <math.h>
3

    
4
// Marsaglia RNG very simple implementation
5
#define znew  ((z=36969*(z&65535)+(z>>16))<<16)
6
#define wnew  ((w=18000*(w&65535)+(w>>16))&65535)
7
#define MWC   (znew+wnew)
8
#define SHR3  (jsr=(jsr=(jsr=jsr^(jsr<<17))^(jsr>>13))^(jsr<<5))
9
#define CONG  (jcong=69069*jcong+1234567)
10
#define KISS  ((MWC^CONG)+SHR3)
11

    
12
#define MWCfp MWC * 2.328306435454494e-10f
13
#define KISSfp KISS * 2.328306435454494e-10f
14

    
15
int InsideCircle(unsigned int iterations,
16
                 unsigned int seed_w,unsigned int seed_z)
17
{
18
   unsigned int z=seed_z;
19
   unsigned int w=seed_w;
20
   unsigned int i;
21

    
22
   int total=0;
23

    
24
   for (i=0;i<iterations;i++) {
25

    
26
      float x=MWCfp ;
27
      float y=MWCfp ;
28

    
29
      // Matching test
30
      int inside=((x*x+y*y) < 1.0f) ? 1:0;
31
      total+=inside;
32
   }
33

    
34
   return(total);
35
}