bonjour,

dans le cadre d'un travail, je dois utiliser le random de la librarie boost

pour cela , j'ai une classe random que voici.


Random.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
#ifndef RANDOM_HPP
#define RANDOM_HPP
 
#include <boost/random.hpp>
 
#include "Singleton.hpp"
 
const double PI = 3.14159265358979323846;
 
class CRandom : public CSingleton<CRandom>{
 
    friend class CSingleton<CRandom>;
 
    private: 
 
		static boost::mt19937 rand_gen;
 
		static boost::uniform_01<boost::mt19937> uni;
		static boost::normal_distribution<double> norm;
		static boost::normal_distribution<double> norm_P;
		static boost::triangle_distribution<double> tri;
		static boost::exponential_distribution<double> expo;
 
		static boost::variate_generator
		    <boost::mt19937&,boost::normal_distribution<double> > normal;
		static boost::variate_generator
		    <boost::mt19937&,boost::normal_distribution<double> > normal_P;
		static boost::variate_generator
		    <boost::mt19937&,boost::triangle_distribution<double> > triangle;
		static boost::variate_generator
		    <boost::mt19937&,boost::exponential_distribution<double> > expon;
 
     CRandom(){};
 
    public:  
		 double Rand(bool P=false);
};
 
 
#endif

et voici le fichier .cpp

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
#include "Random.hpp"
#include "General.hpp"
 
boost::mt19937 CRandom::rand_gen(std::time(NULL));
 
boost::uniform_01<boost::mt19937> CRandom::uni(rand_gen);
 
boost::normal_distribution<double> CRandom::norm(0,1);
boost::variate_generator <boost::mt19937&,
		boost::normal_distribution<double> >
			CRandom::normal(CRandom::rand_gen,norm);
 
boost::normal_distribution<double> CRandom::norm_P(PI,PI);
boost::variate_generator <boost::mt19937&,
		boost::normal_distribution<double> > 
			CRandom::normal_P(CRandom::rand_gen,norm_P);
 
boost::triangle_distribution<double> CRandom::tri(0,1,1);
boost::variate_generator <boost::mt19937&,
		boost::triangle_distribution<double> > 
			CRandom::triangle(CRandom::rand_gen,tri);
 
boost::exponential_distribution<double> CRandom::expo(PI);			
boost::variate_generator <boost::mt19937&,
		boost::exponential_distribution<double> > 
			CRandom::expon(CRandom::rand_gen,expo);
 
 
double CRandom::Rand(bool P){
		double a;
		if(GENERAL.distribution == UNIFORM){
			a= uni();
		}else  if(GENERAL.distribution == NORMAL){
			if (P) a= normal_P();
			else a = normal();		
		}else  if(GENERAL.distribution == TRIANGLULAIRE){
			a = triangle();
		}else  if(GENERAL.distribution == EXPO){
			a = expon();
		}
		return a;
 
 
}

comme vous le voyez, ce truc est immonde et c'est statique (quand je veux changer qqch, je dois tout recompiler) . en fait, ce que j'aimerais, c'est pouvoir choisir dynamiquement les parametres des distributions (par exemple choisir a l'execution le parametre de la distribution exponentiel, ou bien ne pas avoir deux distribution normal, mais 1 dont je peux choisir les parametres.)

le probleme est que je ne m'y connait absolument pas en boost pour pouvoir faire cela. si qqn pouvait me montré pour que j'apprenne.

merci

a+++