00001
00002 #ifndef _SAMPLER_H
00003 #define _SAMPLER_H
00004
00005 #include <cstdlib>
00006 #include <time.h>
00007
00008
00009 namespace gk {
00010
00011
00012 class Sampler
00013 {
00014 public:
00015 Sampler( ) {}
00016
00017
00018 float uniformFloat( )
00019 {
00020 return (float) rand() / (float) RAND_MAX;
00021 }
00022
00023
00024 int uniformInt( const int max )
00025 {
00026 return ((float) rand() * (float) max / (float) RAND_MAX) + .5f;
00027 }
00028
00029
00030 static void init( const int seed= 0 )
00031 {
00032 if(seed != 0)
00033 srand(seed);
00034 else
00035 srand(time(NULL));
00036 }
00037 };
00038
00039 }
00040
00041 #endif