source: cpp/geno_fx/rndutil.cpp @ 182

Last change on this file since 182 was 66, checked in by Maciej Komosinski, 14 years ago

set 'eol-style' to 'native'

  • Property svn:eol-style set to native
File size: 814 bytes
RevLine 
[66]1#include "rndutil.h"
2#include "nonstd.h"
3#include <stdlib.h>
4
5unsigned short pseudornd(short x)
6{
7static long seed=0;
8long y;
9if (x<=0) {seed=-x; return 0;}
10seed=(y=(3677*seed+3680)&0x7fffffff)-1;
11return ((unsigned short)y)%(x);
12}
13
14double CustomRnd(double *tab)
15{
16double *range=tab+1+2*randomN((int)(0.5+tab[0]));
17return range[0]+rnd0N(range[1]-range[0]);
18};
19
20double RandomGener::Uni(float pocz, float kon)
21{
22return pocz+(double)rand()*(kon-pocz)/RAND_MAX;
23}
24
25double RandomGener::GaussStd()
26{
27if (isNextGauss) {isNextGauss=0; return nextGauss;}
28double v1,v2,s;
29do {
30v1=2*rnd01-1; //-1..1
31v2=2*rnd01-1; //-1..1
32s=v1*v1+v2*v2;
33} while (s>=1);
34double mult=sqrt(-2*log(s)/s);
35nextGauss=v2*mult;
36isNextGauss=1;
37return v1*mult;
38}
39
40double RandomGener::Gauss(float m,float s)
41{return m+s*GaussStd();}
42
43RandomGener RndGen;
Note: See TracBrowser for help on using the repository browser.