Random Class Reference

#include <random.h>

List of all members.

Public Member Functions

 Random ()
bool GetBool ()
long GetLong (long min, long max)
double GetDouble ()
double GetDouble (double max)
double GetDouble (double min, double max)
Point2i GetPoint (const Rectanglei &rect)
Point2i GetPoint (const Point2i &pt)


Detailed Description

Definition at line 28 of file random.h.


Constructor & Destructor Documentation

Random::Random (  ) 

Definition at line 30 of file random.cpp.

00030               {
00031   srand( time(NULL) );
00032 }


Member Function Documentation

bool Random::GetBool (  ) 

Definition at line 34 of file random.cpp.

00034                     {
00035   int moitie = RAND_MAX/2;
00036   return (rand() <= moitie);
00037 }

Here is the caller graph for this function:

double Random::GetDouble ( double  min,
double  max 
)

Definition at line 56 of file random.cpp.

00056                                               {
00057         return min + GetDouble(max - min);
00058 }

Here is the call graph for this function:

double Random::GetDouble ( double  max  ) 

Definition at line 60 of file random.cpp.

00060                                   {
00061         return max * GetDouble();
00062 }

Here is the call graph for this function:

double Random::GetDouble (  ) 

Get a random number between 0.0 and 1.0

Returns:
A number between 0.0 and 1.0

Definition at line 69 of file random.cpp.

00069                         {
00070         return 1.0*rand()/(RAND_MAX + 1.0);
00071 }

Here is the caller graph for this function:

long Random::GetLong ( long  min,
long  max 
)

Génère un nombre entier aléatoire compris dans [min;max]

Definition at line 42 of file random.cpp.

00042                                       {
00043         return min + (long)GetDouble(max - min + 1);
00044 /*  double r = rand();
00045   
00046   r *= (max - min);
00047   r /= RAND_MAX;
00048   if( r >= 0 )
00049           r = floor(r + 0.5);
00050   else
00051           r = ceil(r - 0.5);
00052   
00053   return min + (long)r; */
00054 }

Here is the call graph for this function:

Here is the caller graph for this function:

Point2i Random::GetPoint ( const Point2i pt  ) 

Definition at line 87 of file random.cpp.

00087                                          {
00088         return Point2i( GetLong(0, pt.x - 1), GetLong(0, pt.y - 1) );
00089 }

Here is the call graph for this function:

Point2i Random::GetPoint ( const Rectanglei rect  ) 

Return a random point in the given rectangle.

Parameters:
rect The rectangle in which the returned point will be.
Returns:
a random point.

Definition at line 79 of file random.cpp.

00079                                               {
00080         Point2i topPoint = rect.GetPosition();
00081         Point2i bottomPoint = rect.GetBottomRightPoint();
00082         
00083         return Point2i( GetLong(topPoint.x, bottomPoint.x), 
00084                         GetLong(topPoint.y, bottomPoint.y) );
00085 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 14:12:21 2007 for Wormux by  doxygen 1.4.7