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 | FunRan(const FunRan& fh);
|
---|
28 | FunRan(void);
|
---|
29 |
|
---|
30 | int_4 BinRandom(void);
|
---|
31 | r_8 Random(void);
|
---|
32 | r_8 RandomInterp(void);
|
---|
33 | protected:
|
---|
34 | void create_DF(bool pdf);
|
---|
35 | };
|
---|
36 |
|
---|
37 | class FunRan2D {
|
---|
38 | public:
|
---|
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);
|
---|
44 | ~FunRan2D();
|
---|
45 | void Random(r_8& x, r_8& y);
|
---|
46 | void BinRandom(int_4& x, int_4& y);
|
---|
47 | private:
|
---|
48 | FunRan* ranX;
|
---|
49 | FunRan** ranY;
|
---|
50 | int_4 nx;
|
---|
51 | };
|
---|
52 |
|
---|
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 | */
|
---|
58 | inline complex< r_8 > ComplexGaussRan(void)
|
---|
59 | {return complex< r_8 >(NorRand(),NorRand());}
|
---|
60 | inline complex< r_8 > ComplexGaussRan(double sig)
|
---|
61 | {return complex< r_8 >(GauRnd(0.,sig),GauRnd(0.,sig));}
|
---|
62 |
|
---|
63 | /*!
|
---|
64 | \ingroup NTools
|
---|
65 | \brief Returns the module of a random complex number generated by ComplexGaussRan
|
---|
66 | */
|
---|
67 | inline double ModComplexGaussRan(double sig=1.)
|
---|
68 | {double r=-log(1.-drand01()); return sig*sqrt(2.*r);}
|
---|
69 |
|
---|
70 | } // namespace SOPHYA
|
---|
71 |
|
---|
72 | #endif
|
---|