Page 1 sur 1

compiling Giac with C++11

Publié : mer. avr. 04, 2018 8:18 am
par lukamar
Hello Bernard,
would Giac compilation fail if the header random.h was included? It belongs to C++11 standard, so I'm not sure. I would like to use it in some new code that I'm preparing. Thanks!

Re: compiling Giac with C++11

Publié : mer. avr. 04, 2018 4:30 pm
par parisse
It would probably fail with some compilers I'm using. At some point, I know that I'll need to switch to C++11 but I'm not impatient because I fear it will raise some headdaches. What random functions do you need?

Re: compiling Giac with C++11

Publié : jeu. avr. 05, 2018 6:58 am
par lukamar
I need simple stuff, just generating a random integer in the given range [m,n) and the standard Gaussian random variable (mean=0 and stddev=1). The latter could be obtained by Box-Muller algorithm, while the former is as easy as m+rand()%(n-m), but it is in fact not uniform (lower numbers are slightly more likely to be returned). I know that Giac implements a better algorithm somewhere, can you point me to it please? I'm using STL containers of integers for speed, so i would like to avoid using gen class when generating random numbers (otherwise they would be easy to obtain by _rand), if possible.

Re: compiling Giac with C++11

Publié : jeu. avr. 05, 2018 7:53 am
par parisse
giac_rand(contextptr) returns a random integer between 0 and rand_max2 (included) and randNorm(contextptr) returns a random double according to the normal law.

Re: compiling Giac with C++11

Publié : jeu. avr. 05, 2018 5:30 pm
par lukamar
Thanks! I'll then use giac_rand(ctx)/(rand_max2+1.0) for generating a real in [0,1[ and giac_rand(ctx)%n for an integer in [0,n-1].