Jump to content

Paulp51d

New Members
  • Posts

    5
  • Joined

  • Last visited

Paulp51d's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Well thanks all, I really appreciate the help. Of course I understand that the randomly generated numbers would not actually really prove anything, but It would look and feel like an authentic procedure. And don't forget I was wanting to explore what could be done with PHP - which you have helped me to do. Thanks.
  2. HI guys. Thanks for the answers, which I really appreciate. Mostly I am doing this as a learning exercise for, but with a live website in mind as well. I had a competition in mind, where the entrants would leave their name and address and be assigned a number. If I limited the competition to 300 entrants, then each person would acquire a number from 1-300, sequentially. If I then said that the randomly selected winner would be drawn on 1st July, 2015 say, I was thinking that the page could flash up a random number between 1 and 300, every 10 seconds, say, until the draw date. I could then have a countdown timer on the page and when the clock stopped the last randomly generated number wins. The purpose of having the randomly generated number appearing on the screen every few seconds would simply be to illustrate that the competition was honest and above board. So, you think that this is not really do-able or sensible? Paul
  3. 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 } ?>
×
×
  • 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.