homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

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)

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)

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)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved