1/* ************************************************************************* */ 2/* */ 3/* Included Files */ 4/* */ 5/* ************************************************************************* */ 6 7#include <fcntl.h> 8#include <math.h> 9#include <stdio.h> 10#include <unistd.h> 11#include "libcsc.h" 12 13 14/* ************************************************************************* */ 15/* */ 16/* Executable Code - MAIN */ 17/* */ 18/* ************************************************************************* */ 19 20int main (void) 21 { 22 int ab; 23 int ac; 24 double px; 25 double py; 26 int i; 27 int j; 28 int y; 29 double d; 30 31 for (j=0 ; j<5 ; j++) 32 { 33 34 if (access("/dev/random",R_OK) == 0) 35 { 36 int fd = open ("/dev/random", O_RDONLY); 37 (void)read (fd, &y, 4); 38 (void)close (fd); 39 } 40 else 41 { 42 y = 0xAAAAAAAA; 43 } 44 45 ab = 0; 46 ac = 0; 47 48 for (i=0 ; i<4000000 ; i++) 49 { 50 y = CSCurand (y, &d); px = d; 51 y = CSCurand (y, &d); py = d; 52 if (((px*px)+(py*py)) > 1.0) 53 ab += 1; 54 else 55 ac += 1; 56 } 57 58 printf ("pi = %8.6f\n", ((float)4.0*(float)ac/((float)ab+(float)ac))); 59 60 } 61 62 exit (0); 63 } 64 65/* End of file. */ 66