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