Jump to content

I need 2 different variables


Tandem

Recommended Posts

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:
[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);
}
}
?>[/code]
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.
Link to comment
Share on other sites

Guest
This topic is now 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.