homepage Welcome to WebmasterWorld Guest from 54.227.40.166
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Visit PubCon.com
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
deviss




msg:4289916
 3:44 am on Mar 31, 2011 (gmt 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

 

Matthew1980




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

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

IntegrityWebDev




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

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

deviss




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

anyone can help with a complete code or guide?

IntegrityWebDev




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