[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] Uniform random number generation
From: |
ozgur |
Subject: |
[Help-gsl] Uniform random number generation |
Date: |
Wed, 26 Nov 2008 15:51:58 +0200 |
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;
};
--
Ozgur
- [Help-gsl] Uniform random number generation,
ozgur <=