Welcome to WebmasterWorld Guest from 54.144.107.83

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Help with a random numbers generator script

     
3:44 am on Mar 31, 2011 (gmt 0)

New User

joined:Mar 31, 2011
posts:7
votes: 0


Hello

I've got a php script that generates random number every page refresh as it's shown below


<?php
srand ((double) microtime( )*1000000);
$random_number = rand(1000,5000);
echo "$random_number";
?>



Everything is good but i would like an option over the script that will change the random generated number each x seconds, a value where i can choose on how many seconds another random number will be generated and shown


would appreciate the help
7:03 am on Mar 31, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Feb 22, 2009
posts:1396
votes: 0


Hi there deviss,

Firstly welcome to WebmasterWorld!

When you're wanting to start putting a timer on a script this generally indicates that your going to need a cron job to police it - unless you can get a nifty piece of ajax to do that for you (but that's outside the scope of my knowledge)

WRT the code you supplied - it looks to me like the top line is doing nothing, because your only using the bottom two lines of code.

I think (bearing in mind that its before coffee at the moment :)) that this would still function like this:-

<?php
echo rand(1000,5000);
?>

Of course that's stripped down to bare bones, and there is not much memory usage there as it's a direct echo, and not assigned to memory.

There are bound to be a few suggestions, but as far as setting up a timer, you could have a page refresh or header() call with the delay parameter set, which you could have set in a db field somewhere which *could* achieve what your after. Of course this assumes that the page isn't top heavy with content.

Cheers,
MRb
2:36 pm on Mar 31, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 4, 2009
posts: 186
votes: 0


I think you are going to want JS/JQuery for this.
2:18 pm on Apr 5, 2011 (gmt 0)

New User

joined:Mar 31, 2011
posts:7
votes: 0


anyone can help with a complete code or guide?
2:34 pm on Apr 5, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 4, 2009
posts: 186
votes: 0


You will probably want to post your request in the AJAX area to get the code needed.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members