you can limit the number of images with this function:
function get_random_gallery_images(){
global $wpdb,$post;
$ids = "";
$counter = 0;
$number_of_posts = 1;
$args = array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_status' => null,
'orderby' => 'rand',
'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
if ($counter != 0) {
$ids .= ','.$attachment->ID;
}
else {
$ids .= $attachment->ID;
}
$counter++;
}
}
return $ids;
}
output code:
<?php
$attachment_ids = get_random_gallery_images();
echo do_shortcode('[gallery columns="3" include="'.$attachment_ids.'" link="file"]');
?>