homepage Welcome to WebmasterWorld Guest from 54.167.249.155
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 / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Help with a random numbers generator script.
deviss




msg:4293729
 4:32 pm on Apr 7, 2011 (gmt 0)

Created the thread here from users recommandation, hopefully someone can help

[webmasterworld.com...]


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

 

Fotiman




msg:4293738
 4:52 pm on Apr 7, 2011 (gmt 0)

Would something like this work?

<?php
srand ((double) microtime( )*1000000);
$random_number = rand(1000,5000);
echo "$random_number";
?>
<script>
setTimeout(function () {
window.location.reload();
}, 10000); // reload after 10 seconds
</script>

Or do you need to get this via AJAX?

jalarie




msg:4294620
 3:20 pm on Apr 9, 2011 (gmt 0)

If you did the coding in JavaScript instead of PHP, you could avoid both the reload and AJAX.

trader




msg:4294630
 3:50 pm on Apr 9, 2011 (gmt 0)

I am wondering what a random number with every page refresh could be used for?

deviss




msg:4304130
 2:59 pm on Apr 26, 2011 (gmt 0)

Hello sorry for my late response

Thanks for your help Fotiman

Unfortunately, the random number changes each page refresh. I don't want to do that.

Even if i would refresh the page, that number should change after a certain time i set,like in your scrit 10 seconds for example. But your script refreshes it after 10 seconds automatically. But if i refresh the page manually it will show a different number every time i do that.

Hope you can help me

Fotiman




msg:4304201
 4:30 pm on Apr 26, 2011 (gmt 0)

It sounds, then, that what you really need is some sort of cron job running on the server that will generate the value and persist it to a database or file which can then be read by your PHP script. It doesn't sound like a JavaScript issue, though, so you might try a forum that focuses on server side.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
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