FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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.
Related topics
Google stands alone against random samples of our searches
question : how to display random image in main page?
directadmin login
CALLING ALL ACTIONSCRIPTERS, NEED HELP ASAP (IM SERIOUS)
Random picture in Flash..
Random Links
Make an random password..
Need Help : Dreamweaver sessions
encrypt and decrypt PROBLEM plss HELP!
Help with Javascript Aquarium
Random issue
Random images from directory
[Java] Wanna help me figure out this error?
My Class Blog - Help me out
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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