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
RevLine 
[220]1// This may look like C code, but it is really -*- C++ -*-
2// Nombres aleatoires pour Peida.
[3600]3// 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>
[3608]12#include "tvector.h"
[220]13#include "histos.h"
[3075]14#include "srandgen.h"
[3109]15#include "classfunc.h"
[3075]16#include <complex>
[220]17
[1371]18namespace SOPHYA {
19
[220]20class FunRan : public Histo {
21public:
[1092]22 typedef r_8 (*Func)(r_8);
[3109]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);
[3608]27 FunRan(TVector<r_8>& tab, bool pdf=true);
28 FunRan(TVector<r_8>& tab, r_8 xMin, r_8 xMax, bool pdf=true);
[2840]29 FunRan(Histo &h, bool pdf=true);
[3321]30 FunRan(const FunRan& fh);
31 FunRan(void);
32
[3109]33 int_4 BinRandom(void);
[1092]34 r_8 Random(void);
[3109]35 r_8 RandomInterp(void);
36protected:
37 void create_DF(bool pdf);
[220]38};
39
[1371]40class FunRan2D {
[220]41public:
[1092]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);
[220]47 ~FunRan2D();
[1092]48 void Random(r_8& x, r_8& y);
49 void BinRandom(int_4& x, int_4& y);
[220]50private:
51 FunRan* ranX;
52 FunRan** ranY;
[1092]53 int_4 nx;
[220]54};
55
[3100]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*/
[3598]61inline complex< r_8 > ComplexGaussRan(void)
62 {return complex< r_8 >(NorRand(),NorRand());}
63inline complex< r_8 > ComplexGaussRan(double sig)
[3075]64 {return complex< r_8 >(GauRnd(0.,sig),GauRnd(0.,sig));}
65
[3100]66/*!
67 \ingroup NTools
68 \brief Returns the module of a random complex number generated by ComplexGaussRan
69*/
[3097]70inline double ModComplexGaussRan(double sig=1.)
71 {double r=-log(1.-drand01()); return sig*sqrt(2.*r);}
72
[1371]73} // namespace SOPHYA
74
[220]75#endif
Note: See TracBrowser for help on using the repository browser.