Génération de variable aléatoire selon la loi uniform
simsim92
-
ElementW Messages postés 4814 Date d'inscription Statut Contributeur Dernière intervention -
ElementW Messages postés 4814 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour,
j'essaye de faire une classe pour générer des variables aléatoires uniformes dans un intervalle [a,b]
pour cela j'ai fait :
generator.h
#ifndef GENERATOR_H
#define GENERATOR_H
class randomUniform(double a, double b)
{
public:
double randomUniform();
double RAND_MAX;
virtual ~randomUniform();
void reset(); //réinitialise l'état interne de la distribution
protected:
private:
};
#endif // GENERATOR_H
/////////////////////////////////////////////////////////////////
generator.cpp
#include "generator.h"
randomUniform()::randomUniform()
{
return rand()/(double)RAND_MAX;
double randomUniform(double a,double b)
{
return (b-a)*randomUniform()+a;
}
long arrondir(double x)//arrondi à l'entier le plus proche
{
long a=(long)x;
if(a+0.5<=x)
return a+1;
else
return a;
}
long randomInteger(long a,long b)
{
double x=randomUniform(a-0.5,b+0.5);
return arrondir(x);
}
}
randomUniform::~randomUniform()
{
}
//////////////////////////////////////////////////////////////////////
#include <iostream>
#include "generator.cpp"
int main(){
srand(time(0));
cin>>a>>endl;
cin>>b>>endl;
unsigned long nombreTests=10000;
unsigned long compte[b+1];
for(int i=0;i<=b;i++)
{
compte[i]=0;
}
for(int i=0;i<nombreTests;i++)
{
compte[randomInteger(a,b)]++;
}
mais cela me donne des erreurs
error: generator.h No such file or directory
error: expected constructor, destrector, or type conversion before '::' token
pourriez vous m'aider s'il vous plaît?
j'essaye de faire une classe pour générer des variables aléatoires uniformes dans un intervalle [a,b]
pour cela j'ai fait :
generator.h
#ifndef GENERATOR_H
#define GENERATOR_H
class randomUniform(double a, double b)
{
public:
double randomUniform();
double RAND_MAX;
virtual ~randomUniform();
void reset(); //réinitialise l'état interne de la distribution
protected:
private:
};
#endif // GENERATOR_H
/////////////////////////////////////////////////////////////////
generator.cpp
#include "generator.h"
randomUniform()::randomUniform()
{
return rand()/(double)RAND_MAX;
double randomUniform(double a,double b)
{
return (b-a)*randomUniform()+a;
}
long arrondir(double x)//arrondi à l'entier le plus proche
{
long a=(long)x;
if(a+0.5<=x)
return a+1;
else
return a;
}
long randomInteger(long a,long b)
{
double x=randomUniform(a-0.5,b+0.5);
return arrondir(x);
}
}
randomUniform::~randomUniform()
{
}
//////////////////////////////////////////////////////////////////////
#include <iostream>
#include "generator.cpp"
int main(){
srand(time(0));
cin>>a>>endl;
cin>>b>>endl;
unsigned long nombreTests=10000;
unsigned long compte[b+1];
for(int i=0;i<=b;i++)
{
compte[i]=0;
}
for(int i=0;i<nombreTests;i++)
{
compte[randomInteger(a,b)]++;
}
mais cela me donne des erreurs
error: generator.h No such file or directory
error: expected constructor, destrector, or type conversion before '::' token
pourriez vous m'aider s'il vous plaît?
A voir également:
- Génération de variable aléatoire selon la loi uniform
- Generation ryzen - Guide
- Generateur mot de passe - Télécharger - Sécurité
- Réinitialiser chromecast 1ere génération - Guide
- Tirage au sort excel aléatoire sans doublon - Forum Excel
- Tirage au sorte d'un nom dans une liste sans répetition - excel ✓ - Forum Excel