How to produce a unique number from combination of 2 numbers in PHP ? For example, combination of these two numbers; 68 and 73, produce X ( X is a unique number). It does not matter how the order of the combination numbers, it should still produce same unique number. E.g: (68,73)=X or (73,68)=X or combination of (1,2)=Y or (2,1)=Y , Y is a different number (because it's unique) from X.
Let me know if you need more information.
I think this problem is similar to my problem but it is written in C#.
I converted this code to PHP :
function getUnique($x, $y){
if($x>$y){
return $y | $x << 32;
} else{
return $x | $y << 32;
}
}
$list = array();
for($i=0 ; $i<100 ;$i++){
$x = rand(1,10); // I just put any random numbers from 1 to 10 so that I can read it easily.
$y = rand(1,10);
$unique = getUnique($x, $y);
$list[$i] = '('.$x.','.$y.')='.$unique;
}
//Find out the results
foreach($list as $ans){
echo $ans.'<br>';
}
But, it does not produce unique numbers. Example from this results:
(2,9)=11
(10,1)=11
(2,9) should produce different number from (10,1).