Random numbers generation

2005-12-07 Thread Lisandro Damian Nicanor Perez Meyer
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, 
QListNodo  listaProximo ) {
 
  const gsl_rng_type * T;
  gsl_rng * r;

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

  gsl_rng_env_setup();
  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



Re: Random numbers generation

2005-12-07 Thread Lisandro Damian Nicanor Perez Meyer
El Mié 07 Dic 2005 15:06, David Dooling escribió:
 On 12/7/05, Aaron M. Ucko [EMAIL PROTECTED] wrote:
  Lisandro Damian Nicanor Perez Meyer [EMAIL PROTECTED] writes:
   ¿Is there any way of making differents results without having to change
   the seed from the outside?
 
  It looks like you can also call gsl_rng_set(r, some_seed); or assign
  directly to gsl_rng_default_seed, at least with the version of gsl
  available in sid (unstable).

 I have found the best approach is to have a default seed (probably the
 default that GSL uses) and allow the setting of an alternative seed
 via a command-line option or input file (using one of the above
 methods).  You do not want the seed to be ``random'', as that makes
 bugs difficult to find.  You want your output to be deterministic,
 even when using random numbers.

 dd
 --
 David Dooling

Well, thank you everyone! You're incredible!

Cheers, Damian.-

-- 
I was married by a judge. I should have asked for a jury.
 -- Groucho Marx