Hi,
I am writing some code as part of a learning exercise. Ultimately, I want to continuously generate random numbers between 0 and 300 and display this as a single, changing random number until a particular future date/time has been reached.
So, given that I am a total newbie, I have begun by experimenting with the while loop, but with unpredictable results.
I have commented the following code so that you can see what I expect it to do - which is basically keep generating random numbers forever, as the future date is a long way off.
It appears to work sometimes, other times it just freezes everything up.
I also tried placing the sleep(5); in the while statement to see if that would delay the display of the random numbers, but that always caused it to fail.
Can anybody offer any expert advice.
Thanks
Paul
<?php
// subtract timestamp for the present time from the timestamp of some future date and store it in $values1.
$values1 = mktime(16,0,0,6,14,2015)-time();
while ($values1 > 0) { #Has the future date been reached?
echo rand(0,300). "<br/>"; #No, so generate and display a random number?
$values2 = mktime(16,0,0,6,14,2015); #update the value of $values1, ready for retest in the while loop
$values3 = time(); # I realise that I could have just done $values1 = mktime(16,0,0,6,14,2015)-time() again.
$values1 = $values2 - $values3; # but it doesn't work either way
}
?>