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

Last change on this file since 3608 was 3608, checked in by cmv, 16 years ago

delete de tsfunran.cc,h sans interet + FunRan avec TVector, cmv 29/04/2009

File size: 2.0 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2// Nombres aleatoires pour Peida.
3// 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 "tvector.h"
13#include "histos.h"
14#include "srandgen.h"
15#include "classfunc.h"
16#include <complex>
17
18namespace SOPHYA {
19
20class FunRan : public Histo {
21public:
22 typedef r_8 (*Func)(r_8);
23 FunRan(ClassFunc& f, r_8 xMin=0.0, r_8 xMax=1.0, int_4 nBin=100, bool pdf=true);
24 FunRan(Func f, r_8 xMin=0.0, r_8 xMax=1.0, int_4 nBin=100, bool pdf=true);
25 FunRan(r_8 *tab, int_4 nBin, bool pdf=true);
26 FunRan(r_8 *tab, int_4 nBin, r_8 xMin, r_8 xMax, bool pdf=true);
27 FunRan(TVector<r_8>& tab, bool pdf=true);
28 FunRan(TVector<r_8>& tab, r_8 xMin, r_8 xMax, bool pdf=true);
29 FunRan(Histo &h, bool pdf=true);
30 FunRan(const FunRan& fh);
31 FunRan(void);
32
33 int_4 BinRandom(void);
34 r_8 Random(void);
35 r_8 RandomInterp(void);
36protected:
37 void create_DF(bool pdf);
38};
39
40class FunRan2D {
41public:
42// typedef r_8 (*Func)(r_8, r_8);
43// FunRan2D(Func f, r_8 xMin=0.0, r_8 xMax=1.0, int_4 nBinX=100,
44// r_8 yMin=0.0, r_8 yMax=1.0, int_4 nBinY=100);
45 FunRan2D(r_8 *tab, int_4 nBinX, int_4 nBinY);
46 FunRan2D(r_8 **tab, int_4 nBinX, int_4 nBinY);
47 ~FunRan2D();
48 void Random(r_8& x, r_8& y);
49 void BinRandom(int_4& x, int_4& y);
50private:
51 FunRan* ranX;
52 FunRan** ranY;
53 int_4 nx;
54};
55
56
57/*!
58 \ingroup NTools
59 \brief Returns a random complex number such that real and imaginary parts are gaussians with variance sig^2
60*/
61inline complex< r_8 > ComplexGaussRan(void)
62 {return complex< r_8 >(NorRand(),NorRand());}
63inline complex< r_8 > ComplexGaussRan(double sig)
64 {return complex< r_8 >(GauRnd(0.,sig),GauRnd(0.,sig));}
65
66/*!
67 \ingroup NTools
68 \brief Returns the module of a random complex number generated by ComplexGaussRan
69*/
70inline double ModComplexGaussRan(double sig=1.)
71 {double r=-log(1.-drand01()); return sig*sqrt(2.*r);}
72
73} // namespace SOPHYA
74
75#endif
Note: See TracBrowser for help on using the repository browser.