Forum Moderators: coopster

Message Too Old, No Replies

How to combine these two.

         

Simone100

8:57 am on Nov 16, 2006 (gmt 0)

10+ Year Member



Hi I am trying to call something by second and randomly. The first calls something by second. The second calls something randomly. How to combine them so it calls something randomly and by second? Please let me know, thank you very much.

$getfile = rand(0,59);
$getfile = date("s");

eelixduppy

11:50 am on Nov 16, 2006 (gmt 0)



Are you talking about mt_srand [us3.php.net]?

This allows you to specify your own seed, however I don't find that necessary anymore considering PHP does this for you already with rand.


Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.

[us3.php.net...]

Good luck!

Simone100

10:16 pm on Nov 16, 2006 (gmt 0)

10+ Year Member



No, I don't think so, that page doesn't sound like what I need. I am just trying to call something by second or minute but also randomly at the same time.

eelixduppy

4:14 am on Nov 17, 2006 (gmt 0)



So you want to randomly generate a time value in seconds? Isn't this similar to what you have --> $getfile = rand(0,59);?

Maybe if you explained a little but more about what you are trying to accomplish I'll be able to help you better.

Sorry for my misunderstanding; I really wish to help you with this.

Simone100

8:58 am on Nov 17, 2006 (gmt 0)

10+ Year Member



Thank you so much! You sound very, very, nice. Thanks for helping. What I have here
$getfile = rand(0,59);

....Just picks a number between 0 and 59 each time the page is loaded. I need something that changes randomly per second or minute as well.

I realize that seems like it shouldn't matter because whether someone loads the page every second or every minute it will still be a new random item. But my next step is to try to put some type of timer on it so it changes automatically right before your eyes. But one problem and one step at a time. First I need to get it to pick an item per second or minute randomly, I can figure out how to reload the page automatically later. Hope that clears it up, if not just ask. Thanks!

eelixduppy

5:52 pm on Nov 18, 2006 (gmt 0)



I guess it really depends on your application of this, however javascript seems to be a much better path that php. I'm not javascript expert, but something like this should get you started:

javascript code


alert(Math.round(Math.random()*59)); //gives you a random number from 0-59

You can then implement setTimeout() to have a 1 second interval between random numbers generated.

If you like this solution that the Javascript Forum would be a much better place to continue this thread.

I really really hope this help you, because so far I haven't done much.

Best of luck! ;)

Simone100

3:00 am on Nov 19, 2006 (gmt 0)

10+ Year Member



Thank you very much, I really need php though, I need the content to be searched by search engines. So if anyone knows, please let me know. Thanks!

inveni0

3:21 am on Nov 19, 2006 (gmt 0)

10+ Year Member



The problem with PHP is that the page will not finish loading until all PHP processes are complete. You will need to use Javascript in some fashion.

For instance, write your random information via php, but use javascript to refresh the page after 'x' amount of time. This would cause a new php variable.

The problem with Javascript is that most search spiders don't care (or stick around long enough) to enable JS to do what it needs to do.

So, you could try Pearl/CGI. <--that may be your best bet...but even still.....

Search engines are designed to be quick and efficient. Making it stick around for content is a bad idea.

Simone100

5:24 am on Nov 19, 2006 (gmt 0)

10+ Year Member



Thanks, I found out how to make it keep executing, with a page refresh command. But I still need to know how to have the random items change by seconds.