I have a little problem with my generation of random numbers (that follow a standard normal distribution).
In fact I created my little prog which fills me with an array of 10 float by float chosen according to Gauss' law:
And I want to use a hand, the problem is that when I use multiple times "RandomGauss ()" in my hands, it simulates every time the same random distribution ...Code:# # include <iostream> # #include <cmath> # include <cmath> # #include <cstdio> # include <cstdio> # #include <cstdlib> # include <cstdlib> # #include <ctime> # include <ctime> # #include "gauss.h" # include "gauss.h" # # using namespace std; using namespace std; # # # double frand( double a, double b){ FRAND double (double a, double b) ( # # return ( rand()/( double )RAND_MAX ) * (ba) + a; return (rand () / (double) RAND_MAX) * (ba) + a; # } ) # # void RandomGauss( float * y) RandomGauss void (float * y) # { ( # srand(( unsigned int ) time(NULL)); srand ((unsigned int) time (NULL)); # // methode de Box-Muller / / Box-Muller # for ( int i=0;i<10;i++){ for (int i = 0; i <10; i + +) ( # y[i] = sqrt(-2*log(frand(0,1)))*cos(2.*3.14*frand(0,1)); y [i] = sqrt (-2 * log (FRAND (0.1))) * cos (2 .* 3.14 * FRAND (0.1)); # # } ) # } )
For those who will say what needs to srand blabla, it works does not it already appears in my and my gauss.cpp main.cpp
Thank you in advance



Reply With Quote
Copyright Techfuels
Bookmarks