Assuming it's working, (e.g., your script is constructing a valid URI for loading the image in the first place), you'd link the img by simply opening an anchor tag prior to the image tag, then closing it. I prefer echo, but either should work:
echo "<a href=\"$imgpath/".$imgArray[$randval]/"\">
<IMG SRC=\"$imgpath/" . $imgArray[ $randval ] . "\">
</a>";
Hmm, as to your second question, you'd probably want to enclose the whole randomizer in a while() loop, create another array and store each $randval in it ... then, insert an "if" statement after you compute $randval each time, something like:
$storedRandomsArray=array();
while (!$randval) {
mt_srand( (double)microtime( ) * 1000000 );
$randval = mt_rand( 0, sizeof( $imgArray ) - 1 );
if (in_array($randval, $storedRandomsArray)) {
$randval=0;
} else {
$storedRandomsArray[]==$randval;
}
}
HTH,