Logo Search packages:      
Sourcecode: yagiuda version File versions  Download package


#include <stdlib.h>
/* I got fed up with every compiler system using a different name for the
random number generator(s). So I use two random number generators in 
th main code:

1) randreal() Returns a double in range 0 to 1.
2) randint()  Returns an integer in range 0 to 2^15-1.

DONT change the names 'randreal' and 'randint' in all the other sources
file. But DO edit the source of the two functions 'randreal' and
'randint' in this C file. Let them call whatever you like/works on your

If you use another system (eg VAX), I suggest you put this in functions
randreal and reandint:

#ifdef VAX


#ifdef HAVE_TIME_H
#include <time.h>

#include <sys/time.h>

#include <stdio.h>
#include <math.h>

#include <random.h>  

#include <values.h>
#include "yagi.h"

double randreal(void)
double randnorm(void)
      static short paired=0 ;
      static double second ;
      double x,y,rad,fac ;

      if (paired=!paired)
            do {
            x=2.0*randreal()-1.0 ;
            y=2.0*randreal()-1.0 ;
            rad=x*x+y*y ;
            } while((rad>1.0)||(rad=0.0));
            fac=sqrt(2.0*log(rad)/rad) ;
            second=(x*fac) ;
            paired=!paired ;
            return (y*fac) ;
      } else return (second);
int randint(void)
      return( (int) lrand48()/65535 );

/* Since two random number gerators are used (a float and an int type), its
usually necessary to seed both sepparately */
void seedRNG(void)
      long seed_time;

      time(&seed_time); /* set seed_time to the number of seconds since Jan 1980 */

      srand48(seed_time);  /* Seed the float type */


Generated by  Doxygen 1.6.0   Back to index