dice.h

Go to the documentation of this file.
00001 #ifndef DICE_H
00002 #define DICE_H
00003 
00004 #include <cmath>
00005 #include <cstdlib>
00006 
00014 //namespace ?
00015 
00016 class Dice{
00017 public:
00018 /* This is the worst random number routine in the known universe, but
00019    I use it for portability. Feel free to replace it. */
00020 static double uniform_random(void)
00021 {
00022   return (double) rand() / (double) RAND_MAX;
00023 }
00024 
00025 /* This Gaussian routine has been taken from Numerical Recipes and is their
00026    copyright --> to be fixed ?!!!?. */
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

[GNU/Linux] [Qt] [Mesa] [STL] [Lapack] [Boost] [Magick++] [Xalan-C and Xerces-C] [doxygen] [graphviz] [FFTW] [popt] [xine] [Gnuplot] [gnu-arch] [gcc] [gstreamer] [autoconf/automake/make] [freshmeat.net] [opensource.org] [sourceforge.net] [MMVL]
mimas 2.1 - Copyright Mon Oct 30 11:31:17 2006, Bala Amavasai, Stuart Meikle, Arul Selvan, Fabio Caparrelli, Jan Wedekind, Manuel Boissenin, ...