source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/Standalone/Hierarchical Systems Demo [OpenGL]/RESOURCES/include/random.h @ 3255

Revision 3255, 731 bytes checked in by szirmay, 15 years ago (diff)
Line 
1#include "includes.h"
2#pragma once
3
4double UnitRandom ();   
5double RangeRandom (double fLow, double fHigh);
6double SymmetricRandom ();
7
8class Halton
9{
10        float value;
11        float inv_base;
12
13public:
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.