Jump to content

[SOLVED] Random Number Problem


burnside

Recommended Posts

Hey, I have a little bit of code :

 

 

 $num = rand(1,10); 

echo $num;
echo $num;
echo $num;

 

And it gived me the same number for all 3 echo's witch is what is expected but rather then having three $numa $numb etc ... is it possible to have $num not display the same number twice?

 

if that makes sence?

Link to comment
Share on other sites

Additionally you could throw it into a function.

 

<?php
function newNum() {
     $num = rand(1,10);
     return $num;
}

echo newNum();
echo newNum();
echo newNum();
?>

 

And as the others have said. If you only randomize once, you only get one random number. If you roll a dice and get a 6, if you look at it two more times without rolling it, it's still a 6 :)  I hope lol.

Link to comment
Share on other sites

Additionally you could throw it into a function.

 

<?php
function newNum() {
     $num = rand(1,10);
     return $num;
}

echo newNum();
echo newNum();
echo newNum();
?>

 

And as the others have said. If you only randomize once, you only get one random number. If you roll a dice and get a 6, if you look at it two more times without rolling it, it's still a 6 :)   I hope lol.

 

Wow, that was a reallllly good analogy.  *has to remember that one*

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.