Re: Random numbers generation
Hi there,
On Wed, 2005-12-07 at 13:51 -0300, Lisandro Damian Nicanor Perez Meyer
wrote:
> ¿Is there any way of making differents results without having to change the
> seed from "the outside"?
If you want a `random' seed for the `random number generator' you can
use the current time, as turned by `time'. Used with a command line
option, is even better.
int main(int argc, char** argv)
{
int seed = 0, default_seed = 0;
for (int i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
switch (argv[i][1]) {
case 's': seed = strtol(argv[i+1], NULL, 0); i++; break;
case 'd': default_seed = 1; break;
...
}
gsl_rng_env_setup();
if (!getenv("GSL_RNG_SEED")) {
if (seed == 0) seed = time();
if (default_seed) seed = 0;
gsl_rng_set(r, seed);
}
else {
...
}
...
}
Yours,
--
___ | Christian Holm Christensen
|_| | -------------------------------------------------------------
| | Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91
_| DK-2200 Copenhagen N Cell: (+45) 24 61 85 91
_| Denmark Office: (+45) 353 25 404
____| Email: cholm@nbi.dk Web: www.nbi.dk/~cholm
| |
Reply to: