Ok, so this is pretty easy.
I'm not going to write the code for you, but I will tell you the steps and functions to make this work effectively.
Step 1:
Php.net/scandir
This will list all files in the directory, and create an array.
Step 2:
Get the amount of files in your newly created array by using the count function. Php.net/count
Step 3:
Once you have the count, create a range to randomly choose from
Php.net/rand
Step 4:
Call the picture from the array and create the a link
SUMMARY:
$directory = 'this/dir';
$array = scandir($directory);
unset($array['1']);
unset($array['0']);
$counts = count($array);
$filename = rand(0,$counts);