← Back to team overview

yade-users team mailing list archive

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

 

Hi,

are you using the latest trunk version?
There we have already enabled C++11, which you seems need for
the compilation of this code.

Cheers,

Anton


2014-08-18 13:56 GMT+02:00 Raphaël Maurin
<question253257@xxxxxxxxxxxxxxxxxxxxx>:
> 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.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to     : yade-users@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~yade-users
> More help   : https://help.launchpad.net/ListHelp


Follow ups

References