src/dice.cxx

00001 //           dice.cxx
00002 //  Tue Jan 29 10:46:10 2008
00003 //  Copyright  2008  Peter L. Berghold
00004 //  <Peter@Berghold.net>
00005 
00006 
00007 #include <stdlib.h>
00008 #include <time.h>
00009 #include <stdio.h>
00010 
00011 #include "dice.hpp"
00012 
00013 static int randomized = 0; 
00014 
00015 void randomize()
00016 {
00017   srand48(time(0L));
00018 }
00019 
00020 int d1d6() {
00021 
00022         if ( randomized == 0 ) {
00023                 randomize();
00024                 randomized=1;
00025         }
00026 
00027   int retval = ((int) ( drand48() * 6.0 )) + 1;
00028         if ( (1 <= retval) && ( retval <= 6)) 
00029                 return retval;
00030         else 
00031                 return d1d6();
00032 
00033 }
00034 
00035 int d2d6() {
00036   return d1d6() + d1d6();
00037 }
00038 
00039 int randxInRange(int min,int max){
00040         if ( randomized == 0 ) {
00041                 randomize();
00042                 randomized=1;
00043         }
00044         int retval = (int) (drand48() * (double)max) + min;
00045         
00046         if ( ( min <= retval ) && ( retval <= max) ) 
00047                 return retval;
00048         else  return randxInRange(min,max);
00049         
00050 }
00051 

Generated on Fri Mar 7 16:40:53 2008 for frpuniverse by  doxygen 1.4.7