I would say to initialize the seed only once when the program starts (ie keep the random generator in a static variable). Also, you could use a more precise time function which returns the number of ticks (CPU cycles) and not the number of seconds or milliseconds.

Maxime Boissonneault

ozgur a écrit :
Hello people;
I 'd ask your advice. I'm implementing a function in C++ which returns n
uniformly distributed doubles.My question is how to seed that function with
random seed in order to produce different random numbers when called again
and again within very short time intervals.When i test it it produces the
same output within close time intervals but works fine when i call it after
a second or something.If you give some code snippets for solution i can
figure it out more easily. Thanks in advance.I'm giving the code below:
**************************************
#include <ctime>
#include <cstdlib>
#include <gsl/gsl_rng.h>

vector<double> rn_uniform(int n)
{
    vector<double> rn_array;
    // Define GSL RNG parameters.
    const gsl_rng_type * T;
    gsl_rng *r;

    T = gsl_rng_taus2; // RNG type
    r = gsl_rng_alloc(T);// Allocate memory


    srand(time(NULL));
    unsigned long l = rand();

    gsl_rng_set(r, l);

    int i;
    for(i=0; i< n; i++)
        {
            double u = gsl_rng_uniform(r);
            rn_array.push_back(u);
        }

    gsl_rng_free(r); // Free memory

    return rn_array;
};




_______________________________________________
Help-gsl mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gsl

Reply via email to