Wordpress random comment with link to post

Task to show random comment with link to post. The decision below. First we get all approved comments. If we have comments we get random number among of existing, then we print comment content, and put link to commented post. Thats all, we spent some time to do it and we hope our solution will be useful for you.   

<?php
           $comments = get_comments("post_id=$post_id&status=approve");
        
           if ($comments) {
           $ndx = mt_rand(1,sizeof($comments)) - 1;
           $comment = $comments[$ndx];
           }
      ?>

      <p><?php echo $comment->comment_content; ?></p>
      <a href="<?php  print get_permalink( $comment->comment_post_ID); ?>" >Read more ...</a>
Rating: 
10 out of 10 based on 3 ratings.