Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

random.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 * FILE: random.h
00003 * AUTHOR: Christopher L
00004 * DATE:   15 March 1993
00005 * PURPOSE:
00006 *   Declares a class/object for generating random numbers.
00007 ***********************************************************************/
00008  
00009 #ifndef _RANDOM_H
00010 #define _RANDOM_H
00011  
00012 #include <stdlib.h>
00013 #include <time.h>
00014  
00015 /**********************************************************************
00016 * CLASS:  Randomizer
00017 *
00018 * PURPOSE:
00019 *   The Randomizer class simply provides a nice interface for the
00020 *   rand and srand functions.  Also, since the only instance of the
00021 *   class is global, the random number generator automatically gets
00022 *   seeded at the beginning of the program.
00023 *
00024 * FUNCTIONS:
00025 *   Value   Returns a random value between 0 and the integer
00026 *       limit-1, inclusive.
00027 *   operator* A different interface for Value:
00028 *       int x = Random * 12;
00029 ***********************************************************************/
00030  
00031 class Randomizer
00032 {
00033   private:
00034     time_t seed;
00035   public:
00036     Randomizer (void);
00037     Value (int limit)  { return (rand () % limit); }
00038     friend int operator* (Randomizer R, int limit)
00039       { return R.Value (limit); }
00040 };
00041  
00042  
00043 extern Randomizer Random;   // Global instance
00044  
00045  
00046 #endif

Generated on Sun Jul 6 23:07:16 2003 for Scotland Yard by doxygen1.2.15