Jump to content

Loop problem


cwarn23

Recommended Posts

Hi, I am trying to reverse a loop but am having some troubles. Below is an example of my problem but I need to find the value of $c in each round of the second loop. Does anybody know how to find the value of $c in the second loop because I'm stuck in the middle of thick woods.

<?php
$a=1;
$b=47;
$c=88;
$tmp=23;
for($i=0;$i<80;$i++) {
$random_number=floor(mt_rand(0,1000));
echo $random_number.'<br>';
$tmp=($tmp+$c+$random_number)*0.5;
$c=$b;
$b=$a;
$a=$tmp;
}


//Now to reverse
echo '<hr>';


$tmp=$a;
for ($i=0;$i<80;$i--) {
$a=$b;
$b=$c;
//$c=(unknown);
//$random_number=(($tmp-$c)-$a)*2;
//$tmp=($tmp-(($random_number*0.5)+$c+$a))*2;
//echo $random_number.'<br>';
}
?>

Also the objective in this script is to find $random_number for each loop round by appending new code instead of altering the original.

Thanks.

Link to comment
Share on other sites

Just an update, I saw that code has an infinit loop so it is as follows.

<?php
$a=1;
$b=47;
$c=88;
$tmp=23;
for($i=0;$i<80;$i++) {
$random_number=floor(mt_rand(0,1000));
echo $random_number.'<br>';
$tmp=($tmp+$c+$random_number)*0.5;
$c=$b;
$b=$a;
$a=$tmp;
}


//Now to reverse
echo '<hr>';


$tmp=$a;
for ($i=0;$i<80;$i++) {
$a=$b;
$b=$c;
//$c=(unknown);
//$random_number=(($tmp-$c)-$a)*2;
//$tmp=($tmp-(($random_number*0.5)+$c+$a))*2;
//echo $random_number.'<br>';
}
?>

And why isn't anyone replying.

Link to comment
Share on other sites

I have not replied cause what you are doing is greek to me.

You loop through 80 times displaying a random number while doing a bunch of other greeky stuff that does nothing to the results of the random number and that you never use elsewhere. Whats to answer?

 

 

HTH

Teamtomic

Link to comment
Share on other sites

Whats to answer?

Basically I need to find the value of $c and $c is the same as what $tmp will be in two loops time. So I need to predict what $tmp will be in two loops time and assign it to $c. Does anyone know how to do that as it would solve not only this problem but part of a bigger problem I am dealing with. Surly something as simple as this can be solved.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.