<?php
$random_posts = new WP_Query();
$random_posts->Query ('orderby=rand&showposts=5');
while ($random_posts->have_posts()): $random_posts->the_post()
?>
<li>
<?php
$files = get_children("post_parent=$id&post_type=attachment&post_mime_type=image");
if($files){
$keys = array_keys($files);
$num=$keys[0];
$thumb=wp_get_attachment_thumb_url($num);
print "<img src='$thumb' alt='".get_the_title()."' style='padding: 8px 12px 4px 7px; float: left;' width='70' height='50'/>";
}else{
print "<img src='<?php if(has_post_thumbnail()) : the_post_thumbnail(); else : ?>' style='padding: 8px 12px 4px 7px; float: left;' alt='".get_the_title()."' width='70' height='50'/>";
}
?>
<a href="<?php the_permalink();?>" rel="bookmark" title="<?php the_title(); ?>">
<?php the_title(); ?></a><br />
</li>
<?php endwhile; ?>