random.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003         FILE: random.h
00004 
00005         DESCRIPTION: Pseudo-random number generator
00006 
00007         CREATED BY: Jeff Kowalski
00008 
00009         HISTORY: Created 11 February 1999
00010 
00011  *>     Copyright (c) 1999, All Rights Reserved.
00012  **********************************************************************/
00013 
00014 #pragma once
00015 #include "maxheap.h"
00016 
00056 class Random: public MaxHeapOperators {
00057     private:
00058         long   m_seed;
00059 
00060     public:
00061         // The constructor will automatically initialize the seed
00063         UtilExport Random ();
00064 
00065         // Analogues of the random rountines from MSVCRT:
00077         UtilExport void    srand (unsigned int seed = 1); // akin to global ::srand
00078 
00084         UtilExport int     rand  ();                      // akin to global ::rand
00085         UtilExport static const int s_rand_max;           // akin to global RAND_MAX
00086 
00097         inline int get(int max_exclusive = s_rand_max+1, int min_inclusive = 0) {
00098             return (this->rand() % (max_exclusive - min_inclusive) + min_inclusive);
00099         }
00100 
00111         inline float getf(float max_exclusive = 1.0f, float min_inclusive = 0.0f) {
00112             return (this->rand() / (s_rand_max+1.0f) * (max_exclusive - min_inclusive) + min_inclusive);
00113         }
00114 };
00115