Jump to content


Photo

I need 2 different variables


  • This topic is locked This topic is locked
1 reply to this topic

#1 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 06 October 2006 - 11:02 PM

Hi,

I have come to a situation where i need 2 variables that are both numbers, and both generated with rand(), and they both have to be different on every occasion.

For example if they both equal 6, then that is bad.

At the moment due to lack of knowledge of what to do properly, i am using the following code:
<?php
if (!empty($something)){
$var1 = rand(1,52);
$var2 = rand(1,52);
if ($var1 == $var2){
$var1 = rand(1,52);
$var2 = rand(1,52);
}
if ($var1 == $var2){
$var1 = rand(1,52);
$var2 = rand(1,52);
}
if ($var1 == $var2){
$var1 = rand(1,52);
$var2 = rand(1,52);
}
}
?>
The chances of them still being the same after this is pretty small, but still possible. What is the proper way to solve my problem?

Thanks in advance.

#2 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 06 October 2006 - 11:12 PM

nvm, i realised to use a while loop.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users