While the chances of a duplicate are slim the only completely sure way to do it is to use a do...while loop and rename it every time an existing one is made, to give a quickly typed pseudocode example
PHP Code:
$uploaded=false;
do{
$randNum=rand(0,99999);
if file+$randnum does not exist
upload file
$uploaded=true;
end if
} while($uploaded==false);