[851] | 1 | /* fonctions pour generateurs aleatoires */
|
---|
| 2 | /* cmv 23/06/94 */
|
---|
| 3 | /* R.Ansari 04/2000 Copie de nbrand.h .c */
|
---|
| 4 |
|
---|
| 5 | #ifndef SRANDGEN_H_SEEN
|
---|
| 6 | #define SRANDGEN_H_SEEN
|
---|
| 7 |
|
---|
| 8 | #include "machdefs.h"
|
---|
| 9 | #include <stdlib.h>
|
---|
| 10 |
|
---|
[3099] | 11 | /* ------- SPECIFIQUE Mac Darwin OSX <= 10.2 (gcc < 3.x) -------- */
|
---|
[2323] | 12 | #if defined(Darwin) && defined(__GNUC__) && (__GNUC__ < 3)
|
---|
[2324] | 13 | #include "osx_values.h"
|
---|
[2323] | 14 | /* Declaration de drand48 et srand48 etc , mis ds SysSpec
|
---|
| 15 | Reza 11/02/2003 */
|
---|
[2324] | 16 | #ifdef __cplusplus
|
---|
| 17 | extern "C" {
|
---|
| 18 | #endif
|
---|
| 19 | unsigned short int * seed48(unsigned short int seed16v[3]);
|
---|
| 20 | void srand48(long seedval);
|
---|
[2323] | 21 | /* Faute de mieux pour le moment : */
|
---|
[2324] | 22 | #ifdef __cplusplus
|
---|
| 23 | }
|
---|
[2323] | 24 | #endif
|
---|
[2324] | 25 | #define drand48() ((double)(random())/LONG_MAX)
|
---|
| 26 | #endif
|
---|
[3099] | 27 | /* ------- FIN SPECIFIQUE Mac OSX / Darwin V <= 10.2 --------- */
|
---|
[2323] | 28 |
|
---|
[3099] | 29 | #ifdef __cplusplus
|
---|
| 30 | /* Declaration en fonctions inlines pour du C++ */
|
---|
| 31 | inline float frand01() { return ( (float) drand48() ); }
|
---|
| 32 | inline double drand01() { return ( drand48() ); }
|
---|
| 33 | inline double ranf01() { return ( drand48() ); }
|
---|
| 34 |
|
---|
| 35 | inline float frandpm1() { return ( 2. * (float) drand48() - 1.); }
|
---|
| 36 | inline double drandpm1() { return ( 2. * drand48() - 1.); }
|
---|
| 37 | inline double ranfpm1() { return ( 2. * drand48() - 1.); }
|
---|
| 38 | #else
|
---|
| 39 | /* les memes en define pour du C */
|
---|
[851] | 40 | #define frand01() ( (float) drand48() )
|
---|
| 41 | #define drand01() ( drand48() )
|
---|
| 42 | #define ranf01() drand01()
|
---|
| 43 |
|
---|
| 44 | #define frandpm1() ( 2. * frand01() - 1.)
|
---|
| 45 | #define drandpm1() ( 2. * drand01() - 1.)
|
---|
| 46 | #define ranfpm1() drandpm1()
|
---|
[3099] | 47 | #endif
|
---|
[851] | 48 |
|
---|
| 49 | struct tirage_alea {
|
---|
| 50 | int Nbin;
|
---|
| 51 | double Min,Max,Lbin;
|
---|
| 52 | double *Tab;
|
---|
| 53 | };
|
---|
| 54 | typedef struct tirage_alea TIREALEA;
|
---|
| 55 |
|
---|
| 56 | #ifdef __cplusplus
|
---|
| 57 | extern "C" {
|
---|
| 58 | #endif
|
---|
| 59 |
|
---|
| 60 | void Ini_Ranf_Quick(long seed_val, int lp);
|
---|
| 61 | void Ini_Ranf(unsigned short seed_16v[3], int lp);
|
---|
| 62 | void Get_Ranf(unsigned short seed_16v[3], int lp);
|
---|
| 63 | void Auto_Ini_Ranf(int lp);
|
---|
| 64 |
|
---|
| 65 | void SetGauRange(double range);
|
---|
| 66 | float NorRand1(void);
|
---|
| 67 | double GauRnd1(double am, double s);
|
---|
| 68 | float NorRand(void);
|
---|
| 69 | double GauRnd(double am, double s);
|
---|
| 70 | int NormCo(double *a,double *b
|
---|
| 71 | ,double mx,double my,double sx,double sy,double ro);
|
---|
| 72 | void NormGau(double *x,double *y
|
---|
| 73 | ,double mx,double my,double sa,double sb,double teta);
|
---|
| 74 |
|
---|
[3099] | 75 | int PoissRand(double mu);
|
---|
[3364] | 76 | unsigned long PoissRandLimit(double mu,double mumax /* =10. */ );
|
---|
[3099] | 77 |
|
---|
[851] | 78 | TIREALEA *init_tirage_alea(int nbin,double xmin,double xmax,double (*fonc) (double));
|
---|
| 79 | double tirage_alea(TIREALEA *alea);
|
---|
| 80 | int end_tirage_alea(TIREALEA *alea);
|
---|
| 81 |
|
---|
| 82 | #ifdef __cplusplus
|
---|
| 83 | }
|
---|
| 84 | #endif
|
---|
| 85 |
|
---|
[3099] | 86 | /* -- Declaration d'une classe pour la centralier la doc -- Oct 2006 */
|
---|
| 87 | #ifdef __cplusplus
|
---|
| 88 | namespace SOPHYA {
|
---|
| 89 | class RandomGenerator {
|
---|
| 90 | public:
|
---|
| 91 | /*! \brief Automatic initialization through Auto_Ini_Ranf() */
|
---|
| 92 | static inline void AutoInit(int lp=0) { Auto_Ini_Ranf(lp); return; }
|
---|
| 93 | /*! \brief Return a random number \b r with a flat distribution 0<=r<=1 */
|
---|
| 94 | static inline double Flat01() { return drand48(); }
|
---|
| 95 | /*! \brief Return a random number \b r with a flat distribution -1<=r<=1 */
|
---|
| 96 | static inline double Flatpm1() { return drandpm1(); }
|
---|
| 97 | /*! \brief Return a random number following a zero mean gaussian distribution */
|
---|
| 98 | static inline double Gaussian(double sigma=1.) { return GauRnd(0., sigma); }
|
---|
| 99 | /*! \brief Return a random number following a Poisson distribution with mean \b mu */
|
---|
| 100 | static inline int Poisson(double mu) { return PoissRand(mu); }
|
---|
| 101 | };
|
---|
| 102 | } /* namespace SOPHYA */
|
---|
[851] | 103 | #endif
|
---|
| 104 |
|
---|
[3099] | 105 | #endif
|
---|
| 106 |
|
---|