[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-gsl] how to seed qrng generators?
From: |
Joakim Hove |
Subject: |
Re: [Help-gsl] how to seed qrng generators? |
Date: |
Sun, 12 Jun 2005 06:24:09 +0200 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.2 (gnu/linux) |
Kevin Thornton <address@hidden> writes:
> gsl_rng_env_setup();
> T = gsl_rng_default;
> r = gsl_rng_alloc (T);
Right here you put in a call:
gsl_rng_set(r , seed);
If you do not call this routine explicitly the generator is seeded
wtih a default seed. To actually get a seed you can (at linux at
least) use /dev/random:
unsigned int seed;
FILE *dev_random;
dev_random = fopen("/dev/random","r");
if (dev_random == NULL) {
fprintf(stderr,"Can not open /dev/random - seeding failed\n");
seed = 0;
} else {
fread(&seed , sizeof(seed), 1, dev_random);
fclose(dev_random);
}
This code (or something very close) has been posted here before;
i.e. I am not the true author of this.
HTH - Joakim
--
Joakim Hove
hove AT ift uib no /
Tlf: +47 (55 5)8 27 90 / Stabburveien 18
Fax: +47 (55 5)8 94 40 / N-5231 Paradis
http://www.ift.uib.no/~hove/ / 55 91 28 18 / 92 68 57 04