[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] ran2 and random walks
From: |
Joseph Wakeling |
Subject: |
[Help-gsl] ran2 and random walks |
Date: |
Fri, 07 Jul 2006 12:25:19 +0200 |
User-agent: |
Thunderbird 1.5.0.4 (X11/20060615) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I'm writing some code right now in which a parameter is meant to
fluctuate as a random walk. I'm using ran2 as the rng.
Suppose I write a simple piece of code of the form,
{
int i; double walk, increment;
/* initialise variables */
for(i=0;i<N;++i) {
walk += (ran2_get_double() < 0.5)?-increment:increment;
printf("%g\n",walk);
}
}
This code produces a nice random walk.
Suppose now instead I add to this,
{
int i; double walk, increment;
/* initialise variables */
for(i=0;i<N;++i) {
walk += (ran2_get_double() < 0.5)?-increment:increment;
printf("%g\n",walk);
/* A load of other stuff now happens here,
that also involves the generation of random
numbers with ran2. */
}
}
I've found that the random walk now has huge biases in it.
Can anyone explain why this should be so? Am I doing something
outrageously stupid by letting the random walk and the other material be
generated by the same stream of pseudo-random numbers?
Many thanks,
-- Joe
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFErjZtcjylL0sfzuERAuC4AJ9aWnsQxsevN8q/aijlks0z9HqkggCeI+9H
2rVJW7w0wOmpTbNUs6+Vr3o=
=JI6f
-----END PGP SIGNATURE-----