Welcome to WebmasterWorld Guest from 54.144.231.243

Forum Moderators: open

Help with a random numbers generator script.

   
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
4:52 pm on Apr 7, 2011 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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?
3:20 pm on Apr 9, 2011 (gmt 0)

10+ Year Member



If you did the coding in JavaScript instead of PHP, you could avoid both the reload and AJAX.
3:50 pm on Apr 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am wondering what a random number with every page refresh could be used for?
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
4:30 pm on Apr 26, 2011 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month