00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "CeylanRandomGenerator.h"
00028
00029 #include "CeylanObject.h"
00030 #include "CeylanOperators.h"
00031 #include "CeylanLogPlug.h"
00032
00033 #include <limits.h>
00034
00035
00036
00037 using std::string ;
00038
00039
00040 using namespace Ceylan ;
00041 using namespace Ceylan::Log ;
00042 using namespace Ceylan::Maths ;
00043 using namespace Ceylan::Maths::Random ;
00044
00045
00046
00047 #ifdef CEYLAN_USES_CONFIG_H
00048 #include "CeylanConfig.h"
00049 #endif // CEYLAN_USES_CONFIG_H
00050
00051
00052
00054 const Seed RandomGenerator::DefaultSeed = 1 ;
00055
00056
00057
00058 RandomGenerator::RandomGenerator( Sample lowerLimit, Sample upperLimit,
00059 Seed aSeed ) :
00060 _lowerLimit( lowerLimit ),
00061 _upperLimit( upperLimit ),
00062 _seed( aSeed )
00063 {
00064
00065 #if CEYLAN_DEBUG_RANDOM
00066 LogPlug::trace( "Maths::RandomGenerator constructor called." ) ;
00067 #endif // CEYLAN_DEBUG_RANDOM
00068
00069 if ( _lowerLimit >= _upperLimit )
00070 throw MathsException( "RandomGenerator: lower limit ("
00071 + Ceylan::toString( _lowerLimit )
00072 + " is not strictly inferior to upper limit ("
00073 + Ceylan::toString( _upperLimit ) + ")." ) ;
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 }
00085
00086
00087
00088 RandomGenerator::~RandomGenerator() throw()
00089 {
00090
00091 #if CEYLAN_DEBUG_RANDOM
00092 LogPlug::trace( "Maths::RandomGenerator destructor called." ) ;
00093 #endif // CEYLAN_DEBUG_RANDOM
00094
00095 }
00096
00097
00098
00099 const string RandomGenerator::toString( VerbosityLevels level ) const
00100 {
00101
00102 return "Random generator output ranging from "
00103 + Ceylan::toString( _lowerLimit ) + " to "
00104 + Ceylan::toString( _upperLimit )
00105 + ", with initial seed being " + Ceylan::toString( _seed ) ;
00106
00107 }
00108
00109
00110
00111
00112 RandomGenerator::RandomGenerator( const RandomGenerator & original ) :
00113 Object(),
00114 _lowerLimit( original._lowerLimit ), _upperLimit( original._upperLimit ),
00115 _seed( original._seed )
00116 {
00117
00118 }
00119