Last change
on this file since 3 was
3,
checked in by Maciej Komosinski, 15 years ago

added geno_fx, a base class for genetic operations on genotypes

File size:
857 bytes

Line  

1  #include "rndutil.h"


2  #include "nonstd.h"


3  #include <stdlib.h>


4 


5  unsigned short pseudornd(short x)


6  {


7  static long seed=0;


8  long y;


9  if (x<=0) {seed=x; return 0;}


10  seed=(y=(3677*seed+3680)&0x7fffffff)1;


11  return ((unsigned short)y)%(x);


12  }


13 


14  double CustomRnd(double *tab)


15  {


16  double *range=tab+1+2*randomN((int)(0.5+tab[0]));


17  return range[0]+rnd0N(range[1]range[0]);


18  };


19 


20  double RandomGener::Uni(float pocz, float kon)


21  {


22  return pocz+(double)rand()*(konpocz)/RAND_MAX;


23  }


24 


25  double RandomGener::GaussStd()


26  {


27  if (isNextGauss) {isNextGauss=0; return nextGauss;}


28  double v1,v2,s;


29  do {


30  v1=2*rnd011; //1..1


31  v2=2*rnd011; //1..1


32  s=v1*v1+v2*v2;


33  } while (s>=1);


34  double mult=sqrt(2*log(s)/s);


35  nextGauss=v2*mult;


36  isNextGauss=1;


37  return v1*mult;


38  }


39 


40  double RandomGener::Gauss(float m,float s)


41  {return m+s*GaussStd();}


42 


43  RandomGener RndGen;


Note: See
TracBrowser
for help on using the repository browser.