Change the values of numberposts gallery

Use posts_per_page instead of numberposts

So the $args for the get_posts would be like below and also the param for post_status is wrong. Check the codex for the details here

Also when when you are fetching one attachment it is useless to set a counter for it. You can use the modified function

function get_random_gallery_images(){
    global $wpdb, $post;

    $args = array(
    'post_type' => 'attachment',
    'posts_per_page' => 1,
    'post_status' => 'any',
    'orderby' => 'rand',
    'post_parent' => $post->ID
    );

    $attachments = get_posts( $args );

    if ($attachments) {
        foreach ( $attachments as $attachment ) {
            $ids = $attachment->ID;
        }
    }

    return $ids;
} 

For more details check the codex