source: Sophya/trunk/SophyaLib/NTools/perandom.h@ 3220

Last change on this file since 3220 was 3109, checked in by cmv, 19 years ago

RandomInterp() + documentation FunRan et Tirage gaussien cmv 20/11/06

File size: 1.8 KB
Line 
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
17namespace SOPHYA {
18
19class FunRan : public Histo {
20public:
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);
30protected:
31 void create_DF(bool pdf);
32};
33
34class FunRan2D {
35public:
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);
44private:
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*/
55inline 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*/
62inline double ModComplexGaussRan(double sig=1.)
63 {double r=-log(1.-drand01()); return sig*sqrt(2.*r);}
64
65} // namespace SOPHYA
66
67#endif
Note: See TracBrowser for help on using the repository browser.