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

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

precisions sur ComplexGaussRan cmv 16/10/2006

File size: 1.5 KB
RevLine 
[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"
14#include <complex>
[220]15
[1371]16namespace SOPHYA {
17
[220]18class FunRan : public Histo {
19public:
[1092]20 typedef r_8 (*Func)(r_8);
21 FunRan(Func f, r_8 xMin=0.0, r_8 xMax=1.0, int_4 nBin=100);
22 FunRan(r_8 *tab, int_4 nBin);
23 FunRan(r_8 *tab, int_4 nBin, r_8 xMin, r_8 xMax);
[2840]24 FunRan(Histo &h, bool pdf=true);
[1092]25 r_8 Random(void);
26 int_4 BinRandom(void);
[220]27};
28
[1371]29class FunRan2D {
[220]30public:
[1092]31// typedef r_8 (*Func)(r_8, r_8);
32// FunRan2D(Func f, r_8 xMin=0.0, r_8 xMax=1.0, int_4 nBinX=100,
33// r_8 yMin=0.0, r_8 yMax=1.0, int_4 nBinY=100);
34 FunRan2D(r_8 *tab, int_4 nBinX, int_4 nBinY);
35 FunRan2D(r_8 **tab, int_4 nBinX, int_4 nBinY);
[220]36 ~FunRan2D();
[1092]37 void Random(r_8& x, r_8& y);
38 void BinRandom(int_4& x, int_4& y);
[220]39private:
40 FunRan* ranX;
41 FunRan** ranY;
[1092]42 int_4 nx;
[220]43};
44
[3097]45//! Returns a random complex number such that real and imaginary parts are gaussians with variance sig^2
[3075]46inline complex< r_8 > ComplexGaussRan(double sig=1.)
47 {return complex< r_8 >(GauRnd(0.,sig),GauRnd(0.,sig));}
48
[3097]49//! Returns the module of a random complex number generated by ComplexGaussRan
50inline double ModComplexGaussRan(double sig=1.)
51 {double r=-log(1.-drand01()); return sig*sqrt(2.*r);}
52
[1371]53} // namespace SOPHYA
54
[220]55#endif
Note: See TracBrowser for help on using the repository browser.