Jump to content

Archived

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

Tandem

I need 2 different variables

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.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

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.