title: Generate new random number every 5 seconds PHP
body: <p>I need to update a variable number $x with a new random value every 5 seconds (length not really important). I know how to do it with a finite loop, however if I want it to be continuous and always just update. I know how to do it with just updating the header, but since I dont want the entire page to reload that is not really an option. Below Ive tried to trick it with a infinite loop (not the best way), but what I am also seeing running this is that it gives me the same number over and over. </p>
  
  <p>Any ideas?</p>
  
  <pre><code>    &lt;?php
  
  echo "Random Number Updating &lt;br&gt;";
  $n = 5;
  $x = rand(1,10);
  
  function random() {
      $interval = 5; // Interval in seconds
      srand(floor(time() / $interval)); 
      $x = rand(0, 10); 
      echo "$x";
  }
  
  while ($x &lt;= 6){
   random();   
  }
  
  
  ?&gt;
  </code></pre>