Main Page   Packages   Class Hierarchy   Alphabetical List   Data Structures   File List   Namespace Members   Data Fields   Globals  

Random.cpp

Go to the documentation of this file.
00001 /*
00002  * $Id: Random.cpp,v 1.3 2002/07/15 06:54:04 virtualcasino Exp $
00003  */
00004 #include<Random.h>
00005 #include<time.h>
00006 
00007 Random::Random(){
00008         setClassName("Random");
00009 }
00010 
00011 Random::Random(unsigned int seed){
00012         setClassName("Random");
00013         lock();
00014         srand(seed);
00015         unlock();
00016 }
00017 
00018 unsigned int Random::random(unsigned int max){
00019         lock();
00020         if(max == RAND_MAX){
00021                 max = rand();
00022         }
00023         else{
00024                 max = rand() % max;
00025         }
00026         unlock();
00027         return max;
00028 }
00029 
00030 unsigned int Random::random(int min, int max){
00031         return min + random(abs(max - min + 1));
00032 }
00033 
00034 void Random::autoSeed(){
00035         lock();
00036         srand(time(NULL));
00037         unlock();
00038 }

Powered by:

SourceForge Logo