[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Random numbers generation

Hi everyone! I don't know if this is the best place to ask this, so if it is 
Off Topic, please tell me.

I did this code (which comes from an example in the gsl doc):

void CicloContagio(Control ctrlCopiaExterno, Nodo & nodoContagiado, 
QList<Nodo> & listaProximo ) {
  const gsl_rng_type * T;
  gsl_rng * r;

  /* create a generator chosen by the environment variable GSL_RNG_TYPE */

  T = gsl_rng_default;
  r = gsl_rng_alloc (T);

  for (int i = 0; i < 3; i++) {
    double k = gsl_ran_flat (r,0,1);
    cout << k << "\n\n";
  //more code...

It compiles fine, but there's a little detail. Every time I run the program, I 
get the same results, which is not what I want. 

Reading futher in the documentation:

" The variates depend on the seed used by the generator. The seed for the 
default generator type gsl_rng_default can be changed with the GSL_RNG_SEED 
environment variable to produce a different stream of variates,

$ GSL_RNG_SEED=123 ./a.out "

¿Is there any way of making differents results without having to change the 
seed from "the outside"?

Cheers, Damian.-

Anyone who says he can see through women is missing a lot.
 -- Groucho Marx

Reply to: