For such things, I found a useful php uniqid function. Basically, something like this:
$dirname = uniqid(); mkdir($dirname);
And then just move the downloaded file to this directory.
Edit: forgot to mention, the directory name is not random, but guaranteed to be unique, which seems to be what you need.
source share