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

Last change on this file since 3587 was 3321, checked in by cmv, 18 years ago

createur par copie/default pour FunRan cmv 05/09/2007

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 FunRan(const FunRan& fh);
28 FunRan(void);
29
30 int_4 BinRandom(void);
31 r_8 Random(void);
32 r_8 RandomInterp(void);
33protected:
34 void create_DF(bool pdf);
35};
36
37class FunRan2D {
38public:
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);
47private:
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*/
58inline complex< r_8 > ComplexGaussRan(double sig=1.)
59 {return complex< r_8 >(GauRnd(0.,sig),GauRnd(0.,sig));}
60
61/*!
62 \ingroup NTools
63 \brief Returns the module of a random complex number generated by ComplexGaussRan
64*/
65inline double ModComplexGaussRan(double sig=1.)
66 {double r=-log(1.-drand01()); return sig*sqrt(2.*r);}
67
68} // namespace SOPHYA
69
70#endif
Note: See TracBrowser for help on using the repository browser.