FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

help with random

 


golles
I have a little script that puts a random number between 0 and 25

Code:

<?
srand(time());
$random = (rand()%26);
?>


Is this a good script to get a random number or not?

no I'm will to put in the page title and somewhere on the page a random username random link and a random message (all with the same number)
I was thinking for the title:

Code:

<title>Join <?php echo "$" . "us" . $random ?></title>

That could become $us0 wich will result in golles, but it doesn't the page title would be "Join $us1"

So can someone tell me what I'm doing wrong?
and if the random code is good?
thanks in advance!


//golles
Stubru Freak
Don't really understand what you mean, but instead of
Code:
$random = (rand()%26);


You could also do:
Code:
$random = rand(0, 25);


Seems easier to me...
golles
Stubru Freak wrote:
Don't really understand what you mean, but instead of
Code:
$random = (rand()%26);


You could also do:
Code:
$random = rand(0, 25);


Seems easier to me...

I found that out some minutes ago Wink
ml
Quote:


Code:
<title>Join <?php echo "$" . "us" . $random ?></title>


That could become $us0 wich will result in golles, but it doesn't the page title would be "Join $us1"


well the most elegant way of solving this would be a array for $us

Code:
$us = array(...,..,..);
echo "<title>Join ". $us[$random]."</title>


another way would be

Code:
$username = "us" . $random;
echo "<title>Join ". $$username."</title>
golles
thanks. a mate made a script for me and is now explain the array thing to me.
thanks anyway!
Grimboy
Might want to use microtime()-(time()*1000) instead of time().
Stubru Freak
Grimboy wrote:
Might want to use microtime()-(time()*1000) instead of time().


That's usefull if it has to be completely random, but in this case it seems to me like that's not really important.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.