Jump to content

[SOLVED] Random Number Problem


beansandsausages

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
https://forums.phpfreaks.com/topic/126618-solved-random-number-problem/
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.

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*

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.