Answer the question
In order to leave comments, you need to log in
How to correctly implement a random walk algorithm?
Where can I see the pseudocode or implementation of a random walk? I can't find a solution for the second step.
$steps = 50;
$number = 300;
for ($i = 0 ;$i <= $steps; $i++){
if ($number <= 0)
$newNumber = $number + rand(0,100);
else
$newNumber = $number - rand(0,100);
echo $i . " = " . $newNumber . "\r\n";
}
?>
Answer the question
In order to leave comments, you need to log in
The assignment method doesn't work, I don't know why.
produces strange result
0
300
0 = 234
234
300
1 = 277
277
300
$steps = 50;
$newNumber = 300;
for ($i = 0 ;$i <= $steps; $i++){
echo $newNumber . "\r\n";
if ( $newNumber <= 0 )
$newNumber = $newNumber + rand(0,100);
else
$newNumber = $newNumber - rand(0,100);
echo $i . " = " . $newNumber . "\r\n";
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question