00001 #ifndef DICE_H
00002 #define DICE_H
00003
00004 #include <cmath>
00005 #include <cstdlib>
00006
00014
00015
00016 class Dice{
00017 public:
00018
00019
00020 static double uniform_random(void)
00021 {
00022 return (double) rand() / (double) RAND_MAX;
00023 }
00024
00025
00026
00027
00028 static double gaussian_random(void)
00029 {
00030 static int next_gaussian = 0;
00031 static double saved_gaussian_value;
00032
00033 double fac, rsq, v1, v2;
00034
00035 if (next_gaussian == 0) {
00036 do {
00037 v1 = 2.0*uniform_random()-1.0;
00038 v2 = 2.0*uniform_random()-1.0;
00039 rsq = v1*v1+v2*v2;
00040 } while (rsq >= 1.0 || rsq == 0.0);
00041 fac = sqrt(-2.0*log(rsq)/rsq);
00042 saved_gaussian_value=v1*fac;
00043 next_gaussian=1;
00044 return v2*fac;
00045 } else {
00046 next_gaussian=0;
00047 return saved_gaussian_value;
00048 }
00049 }
00050 };
00051
00052
00053 #endif