Welcome to WebmasterWorld Guest from

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)


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

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)

WebmasterWorld Senior Member 5+ Year Member

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:-

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.



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

5+ Year Member

I think you are going to want JS/JQuery for this.


2:18 pm on Apr 5, 2011 (gmt 0)

anyone can help with a complete code or guide?


2:34 pm on Apr 5, 2011 (gmt 0)

5+ Year Member

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

Featured Threads

Hot Threads This Week

Hot Threads This Month