| 1 | // This may look like C code, but it is really -*- C++ -*-
 | 
|---|
| 2 | // Nombres aleatoires pour Peida.
 | 
|---|
| 3 | //   NON CE N'EST PAS MON CODE ... C. Magneville   1996-2000
 | 
|---|
| 4 | // DAPNIA/SPP (Saclay) / CEA    LAL - IN2P3/CNRS  (Orsay)
 | 
|---|
| 5 | 
 | 
|---|
| 6 | #ifndef PERANDOM_SEEN
 | 
|---|
| 7 | #define PERANDOM_SEEN
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #include "machdefs.h"
 | 
|---|
| 10 | #include <stdlib.h>
 | 
|---|
| 11 | #include <math.h>
 | 
|---|
| 12 | #include "histos.h"
 | 
|---|
| 13 | #include "srandgen.h"
 | 
|---|
| 14 | #include "classfunc.h"
 | 
|---|
| 15 | #include <complex>
 | 
|---|
| 16 | 
 | 
|---|
| 17 | namespace SOPHYA {  
 | 
|---|
| 18 | 
 | 
|---|
| 19 | class FunRan : public Histo {
 | 
|---|
| 20 | public:
 | 
|---|
| 21 |   typedef r_8 (*Func)(r_8);
 | 
|---|
| 22 |   FunRan(ClassFunc& f, r_8 xMin=0.0, r_8 xMax=1.0, int_4 nBin=100, bool pdf=true);
 | 
|---|
| 23 |   FunRan(Func f, r_8 xMin=0.0, r_8 xMax=1.0, int_4 nBin=100, bool pdf=true);
 | 
|---|
| 24 |   FunRan(r_8 *tab, int_4 nBin, bool pdf=true);
 | 
|---|
| 25 |   FunRan(r_8 *tab, int_4 nBin, r_8 xMin, r_8 xMax, bool pdf=true);
 | 
|---|
| 26 |   FunRan(Histo &h, bool pdf=true);
 | 
|---|
| 27 |   int_4 BinRandom(void);
 | 
|---|
| 28 |   r_8 Random(void);
 | 
|---|
| 29 |   r_8 RandomInterp(void);
 | 
|---|
| 30 | protected:
 | 
|---|
| 31 |   void create_DF(bool pdf);
 | 
|---|
| 32 | };
 | 
|---|
| 33 | 
 | 
|---|
| 34 | class FunRan2D  {
 | 
|---|
| 35 | public:
 | 
|---|
| 36 | //  typedef r_8 (*Func)(r_8, r_8);
 | 
|---|
| 37 | //  FunRan2D(Func f, r_8 xMin=0.0, r_8 xMax=1.0, int_4 nBinX=100,
 | 
|---|
| 38 | //                   r_8 yMin=0.0, r_8 yMax=1.0, int_4 nBinY=100);
 | 
|---|
| 39 |   FunRan2D(r_8 *tab, int_4 nBinX, int_4 nBinY);
 | 
|---|
| 40 |   FunRan2D(r_8 **tab, int_4 nBinX, int_4 nBinY);
 | 
|---|
| 41 |   ~FunRan2D();
 | 
|---|
| 42 |   void Random(r_8& x, r_8& y);
 | 
|---|
| 43 |   void BinRandom(int_4& x, int_4& y);
 | 
|---|
| 44 | private:
 | 
|---|
| 45 |   FunRan* ranX;
 | 
|---|
| 46 |   FunRan** ranY;
 | 
|---|
| 47 |   int_4 nx;
 | 
|---|
| 48 | };
 | 
|---|
| 49 | 
 | 
|---|
| 50 | 
 | 
|---|
| 51 | /*!
 | 
|---|
| 52 |   \ingroup NTools
 | 
|---|
| 53 |   \brief Returns a random complex number such that real and imaginary parts are gaussians with variance sig^2
 | 
|---|
| 54 | */
 | 
|---|
| 55 | inline complex< r_8 > ComplexGaussRan(double sig=1.)
 | 
|---|
| 56 |   {return complex< r_8 >(GauRnd(0.,sig),GauRnd(0.,sig));}
 | 
|---|
| 57 | 
 | 
|---|
| 58 | /*!
 | 
|---|
| 59 |   \ingroup NTools
 | 
|---|
| 60 |   \brief Returns the module of a random complex number generated by ComplexGaussRan
 | 
|---|
| 61 | */
 | 
|---|
| 62 | inline double ModComplexGaussRan(double sig=1.)
 | 
|---|
| 63 |   {double r=-log(1.-drand01()); return sig*sqrt(2.*r);}
 | 
|---|
| 64 | 
 | 
|---|
| 65 | } // namespace SOPHYA
 | 
|---|
| 66 | 
 | 
|---|
| 67 | #endif
 | 
|---|