← Back to team overview

yade-users team mailing list archive

[Question #253257]: generate a random number in the C++ code

 

New question #253257 on Yade:
https://answers.launchpad.net/yade/+question/253257

Hi all, 
I need to generate a random number from a gaussian distribution in the C++ code of Yade. 
For that, basing myself on http://www.cplusplus.com/reference/random/normal_distribution/
I wrote in the cpp file : 
#include<random>
std::default_random_engine generator;
std::normal_distribution<double> distribution(0.0,1.0);
double number = distribution(generator);

When compiling, I get an error which I do not understand :

In file included from /usr/include/c++/4.6/random:35:0,
                 from /home/raphael/these/code/Yade/trunk/pkg/common/ForceEngine.cpp:13:
/usr/include/c++/4.6/bits/c++0x_warning.h:32:2: erreur: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
/home/raphael/these/code/Yade/trunk/pkg/common/ForceEngine.cpp: In member function ‘virtual void HydroForceEngine::action()’:
/home/raphael/these/code/Yade/trunk/pkg/common/ForceEngine.cpp:94:3: erreur: ‘default_random_engine’ is not a member of ‘std’
/home/raphael/these/code/Yade/trunk/pkg/common/ForceEngine.cpp:94:30: erreur: expected ‘;’ before ‘generator’
/home/raphael/these/code/Yade/trunk/pkg/common/ForceEngine.cpp:95:3: erreur: ‘normal_distribution’ is not a member of ‘std’
/home/raphael/these/code/Yade/trunk/pkg/common/ForceEngine.cpp:95:28: erreur: expected primary-expression before ‘double’
/home/raphael/these/code/Yade/trunk/pkg/common/ForceEngine.cpp:95:28: erreur: expected ‘;’ before ‘double’
/home/raphael/these/code/Yade/trunk/pkg/common/ForceEngine.cpp:109:27: erreur: ‘generator’ was not declared in this scope
/home/raphael/these/code/Yade/trunk/pkg/common/ForceEngine.cpp:109:36: erreur: ‘distribution’ was not declared in this scope
make[2]: *** [CMakeFiles/yade.dir/pkg/common/ForceEngine.cpp.o] Erreur 1
make[2]: *** Attente des tâches non terminées....
make[1]: *** [CMakeFiles/yade.dir/all] Erreur 2
make: *** [all] Erreur 2


Do you have an idea from where this error come from ? 
If necessary I can put the whole code but I don't think it will bring something. 

Raphaël

-- 
You received this question notification because you are a member of
yade-users, which is an answer contact for Yade.


Follow ups