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

Random Class Reference

#include <newran.h>

Inheritance diagram for Random:

Inheritance graph
[legend]

Public Member Functions

double Get ()
virtual Real Next ()
virtual char * Name ()
virtual Real Density (Real) const
 Random ()
virtual ~Random ()
SelectedRandomoperator() (double)
RepeatedRandomoperator() (int)
virtual ExtReal Mean () const
virtual ExtReal Variance () const
virtual void tDelete ()
virtual int nelems () const
virtual void load (int *, Real *, Random **)
virtual RandomGetrv (void)

Static Public Member Functions

void Set (double s)

Private Member Functions

Real Raw ()
void operator= (const Random &)

Private Attributes

Real Buffer [128]

Static Private Attributes

double seed

Friends

class RandomPermutation

Constructor & Destructor Documentation

Random::Random  ) 
 

Definition at line 168 of file newran.cpp.

References Buffer, and Raw().

00169 {
00170    for (int i = 0; i<128; i++) 
00171            Buffer[i] = Raw();
00172 }

virtual Random::~Random  )  [inline, virtual]
 

Definition at line 45 of file newran.h.

00045 {}                   // make destructors virtual


Member Function Documentation

Real Random::Density Real   )  const [virtual]
 

Reimplemented in Poisson1, Gamma1, Gamma2, Binomial1, Uniform, Normal, Cauchy, Exponential, PosGenX, SymGenX, AsymGenX, and NegativeBinomial.

Definition at line 144 of file newran.cpp.

References Real.

Referenced by AsymGen::Build(), PosGen::Build(), AsymGen::Next(), SymGen::Next(), and PosGen::Next().

00145 { Throw(Logic_error("density function not defined")); return 0.0; }

double Random::Get  ) 
 

Definition at line 165 of file newran.cpp.

References seed.

00166 { return seed/2147483648L; }

virtual Random* Random::Getrv void   )  [inline, virtual]
 

Reimplemented in NegatedRandom.

Definition at line 58 of file newran.h.

00058 {       return 0;       }

void Random::load int *  ,
Real ,
Random ** 
[virtual]
 

Reimplemented in SelectedRandom, and AddedSelectedRandom.

Definition at line 794 of file newran.cpp.

Referenced by AddedSelectedRandom::load().

00795    { Throw(Logic_error("Newran: illegal combination")); }

virtual ExtReal Random::Mean  )  const [inline, virtual]
 

Reimplemented in ChiSq1, Poisson1, Poisson2, Gamma1, Gamma2, Binomial1, Binomial2, Uniform, Constant, PosGen, Normal, ChiSq, Cauchy, Exponential, AsymGen, Gamma, Pareto, DiscreteGen, Poisson, Binomial, NegativeBinomial, NegatedRandom, ScaledRandom, ReciprocalRandom, ShiftedRandom, ReverseShiftedRandom, RepeatedRandom, MultipliedRandom, AddedRandom, OredRandom, SubtractedRandom, DividedRandom, SumRandom, MixedRandom, and OredVectRandom.

Definition at line 48 of file newran.h.

Referenced by alHistogram(), MultipliedRandom::Mean(), SubtractedRandom::Mean(), OredRandom::Mean(), AddedRandom::Mean(), RepeatedRandom::Mean(), ReverseShiftedRandom::Mean(), ShiftedRandom::Mean(), ScaledRandom::Mean(), NegatedRandom::Mean(), and MultipliedRandom::Variance().

00048 { return 0.5; }

char * Random::Name  )  [virtual]
 

Reimplemented in Uniform, Constant, PosGen, SymGen, Normal, ChiSq, Cauchy, Exponential, AsymGen, Gamma, PosGenX, SymGenX, AsymGenX, Pareto, DiscreteGen, Poisson, Binomial, NegativeBinomial, SumRandom, and MixedRandom.

Definition at line 902 of file newran.cpp.

Referenced by alHistogram().

00902 { return "Random";           }

virtual int Random::nelems  )  const [inline, virtual]
 

Reimplemented in AddedSelectedRandom.

Definition at line 53 of file newran.h.

Referenced by AddedSelectedRandom::nelems().

00053 { return 1; }

Real Random::Next  )  [virtual]
 

Reimplemented in ChiSq1, Poisson1, Poisson2, Gamma1, Binomial1, Binomial2, Uniform, Constant, PosGen, SymGen, ChiSq, AsymGen, Gamma, Pareto, DiscreteGen, Poisson, Binomial, NegativeBinomial, NegatedRandom, ScaledRandom, ReciprocalRandom, ShiftedRandom, ReverseShiftedRandom, RepeatedRandom, MultipliedRandom, AddedRandom, OredRandom, SubtractedRandom, DividedRandom, SumRandom, SelectedRandom, AddedSelectedRandom, MixedRandom, and OredVectRandom.

Definition at line 151 of file newran.cpp.

References Buffer, Raw(), Real, and seed.

Referenced by Hist(), Histogram(), ProbaHolder::Next(), Uniform::Next(), RandomPermutation::Next(), RepeatedRandom::Next(), DividedRandom::Next(), MultipliedRandom::Next(), SubtractedRandom::Next(), OredRandom::Next(), AddedRandom::Next(), ReciprocalRandom::Next(), ReverseShiftedRandom::Next(), ShiftedRandom::Next(), ScaledRandom::Next(), NegatedRandom::Next(), DiscreteGen::Next(), Pareto::Next(), ChiSq::Next(), AsymGen::Next(), SymGen::Next(), PosGen::Next(), ProbaHolder::operator[](), ProbaHolder::ProbaHolder(), and DiscreteProba::Setup().

00152 {
00153    if (!seed)
00154       Throw(Logic_error("Random number generator not initialised"));
00155    int i = (int)(Raw()*128);               // 0 <= i < 128
00156 #ifdef _MSC_VER
00157    DoNothing(i); DoNothing(i);
00158 #endif
00159    Real f = Buffer[i]; Buffer[i] = Raw();  // Microsoft release gets this wrong
00160    return f;
00161 
00162    // return Mother(&iseed);
00163 }

RepeatedRandom & Random::operator() int   ) 
 

Definition at line 661 of file newran.cpp.

References ErrorNoSpace().

00662 {
00663    RepeatedRandom* r = new RepeatedRandom(*this, n);
00664    if (!r) ErrorNoSpace(); return *r;
00665 }

SelectedRandom & Random::operator() double   ) 
 

Definition at line 891 of file newran.cpp.

References ErrorNoSpace().

00892 {
00893    SelectedRandom* r = new SelectedRandom(*this, p);
00894    if (!r) ErrorNoSpace(); return *r;
00895 }

void Random::operator= const Random  )  [inline, private]
 

Definition at line 36 of file newran.h.

00036 {}       // private so can't access

Real Random::Raw  )  [private]
 

Definition at line 132 of file newran.cpp.

References Real, and seed.

Referenced by Next(), and Random().

00133 {
00134    // m = 2147483647 = 2^31 - 1; a = 16807;
00135    // 127773 = m div a; 2836 = m mod a
00136    long iseed = (long)seed;
00137    long hi = iseed / 127773L;                 // integer division
00138    long lo = iseed - hi * 127773L;            // modulo
00139    iseed = 16807 * lo - 2836 * hi;
00140    if (iseed <= 0) iseed += 2147483647L;
00141    seed = (double)iseed; return seed*4.656612875e-10;
00142 }

void Random::Set double  s  )  [static]
 

Definition at line 174 of file newran.cpp.

References seed.

Referenced by main(), and Parameters::Parameters().

00176 {
00177    if (s>=1.0 || s<=0.0)
00178       Throw(Logic_error("Newran: seed out of range"));
00179    //iseed = 2147483648L * s;         // for Mother
00180    seed = (long)(s*2147483648L);
00181 }

virtual void Random::tDelete  )  [inline, virtual]
 

Reimplemented in NegatedRandom, ScaledRandom, ReciprocalRandom, RepeatedRandom, MultipliedRandom, SelectedRandom, and AddedSelectedRandom.

Definition at line 52 of file newran.h.

Referenced by MixedRandom::~MixedRandom().

00052 {}              // delete components of sum

virtual ExtReal Random::Variance  )  const [inline, virtual]
 

Reimplemented in ChiSq1, Poisson1, Poisson2, Gamma1, Gamma2, Binomial1, Binomial2, Uniform, Constant, PosGen, Normal, ChiSq, Cauchy, Exponential, AsymGen, Gamma, Pareto, DiscreteGen, Poisson, Binomial, NegativeBinomial, NegatedRandom, ScaledRandom, ReciprocalRandom, ShiftedRandom, ReverseShiftedRandom, RepeatedRandom, MultipliedRandom, AddedRandom, OredRandom, SubtractedRandom, DividedRandom, SumRandom, MixedRandom, and OredVectRandom.

Definition at line 50 of file newran.h.

Referenced by alHistogram(), MultipliedRandom::Variance(), SubtractedRandom::Variance(), OredRandom::Variance(), AddedRandom::Variance(), RepeatedRandom::Variance(), ReverseShiftedRandom::Variance(), ShiftedRandom::Variance(), ScaledRandom::Variance(), and NegatedRandom::Variance().

00050 { return 1.0/12.0; }


Friends And Related Function Documentation

friend class RandomPermutation [friend]
 

Definition at line 56 of file newran.h.


Field Documentation

Real Random::Buffer[128] [private]
 

Definition at line 34 of file newran.h.

Referenced by Next(), and Random().

double Random::seed [static, private]
 

Definition at line 114 of file newran.cpp.

Referenced by Get(), Next(), Raw(), and Set().


The documentation for this class was generated from the following files:
Generated on Fri Dec 5 04:06:33 2003 for Borqueror by doxygen 1.3.3