Rev | Line | |
---|
[852] | 1 | #include "includes.h"
|
---|
| 2 | #pragma once
|
---|
| 3 |
|
---|
| 4 | double UnitRandom ();
|
---|
| 5 | double RangeRandom (double fLow, double fHigh);
|
---|
| 6 | double SymmetricRandom ();
|
---|
| 7 |
|
---|
| 8 | class Halton
|
---|
| 9 | {
|
---|
| 10 | float value;
|
---|
| 11 | float inv_base;
|
---|
| 12 |
|
---|
| 13 | public:
|
---|
| 14 | Halton(long i,int base)
|
---|
| 15 | {
|
---|
| 16 | Number(i,base);
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | void Number(long i,int base)
|
---|
| 20 | {
|
---|
| 21 | float f=inv_base=1.0/base;
|
---|
| 22 | value=0.0;
|
---|
| 23 | while(i>0)
|
---|
| 24 | {
|
---|
| 25 | value+=f*(double)(i%base);
|
---|
| 26 | i/=base;
|
---|
| 27 | f*=inv_base;
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 | void Next()
|
---|
| 31 | {
|
---|
| 32 | float r=1.0-value-0.0000001;
|
---|
| 33 | if(inv_base<r)
|
---|
| 34 | value+=inv_base;
|
---|
| 35 | else
|
---|
| 36 | {
|
---|
| 37 | float h=inv_base,hh;
|
---|
| 38 | do{hh=h;h*=inv_base;}while(h>=r);
|
---|
| 39 | value+=hh+h-1.0;
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 | float Get(){return value;}
|
---|
| 43 | float Random(){
|
---|
| 44 | float n=Get();
|
---|
| 45 | n=2*n-1;
|
---|
| 46 | Next();
|
---|
| 47 | return n;}
|
---|
| 48 | };
|
---|
Note: See
TracBrowser
for help on using the repository browser.