hmm...few notes: What language is that? And it cannot work since all you do is add 1 to ad (variable?) so it's always 1 (remember http is stateless). You can do the same like this (simplified example)
PHP Code:
<?php
$banners = array("image1.jpg", "image2.jpg", "image3.jpg");
<img src="<?php echo $banners[array_rand($banners)]; ?>" alt="Banner" />
?>
save this as banner.php and then on your page require it like
PHP Code:
<?php require_once("banner.php"); ?>