トップオススメ3記事の部分ですが、これを上位10以内からランダムに出したいのですが、どのように変更するのがいいでしょうか?
あと、pickup部分だけ2か月表示させてないのですが、原因がわからないです。

該当のソースコード

<div id="pickup"><div class="itembox"><a href="http:/top/zenpan/482/">
                            <img src="http://image/482.jpg" alt=""></a><p><a href="http:///top/zenpan/482/">a</a></p><div class="countBox"><span class="date">2019.04.23</span><span class="number">211</span></div></div><div class="itembox"><a href="http:///top/lifeplan/494/">
                            <img src="http:/image/494.jpg" alt=""></a><p><a href="http:///top/lifeplan/494/">b</a></p><div class="countBox"><span class="date">2019.06.11</span><span class="number">202</span></div></div><div class="itembox"><a href="http:///top/setsugu/486/">
                            <img src="http:///image/486.jpg" alt=""></a><p><a href="http:///top/setsugu/486/">c</a></p><div class="countBox"><span class="date">2019.05.15</span><span class="number">191</span></div></div><div class="itembox pcsp_only"><a href="http:///top/kiji/340/">
                            <img src="http:///image/340.jpg" alt=""></a><p><a href="http://top/kiji/340/">d</a></p><div class="countBox"><span class="date">2017.10.16</span><span class="number">180</span></div></div>            <p class="ousume_text">
              <a href="http:///recom/">
                  オススメ一覧はこちら
              </a>
            </p>
          </div>
<?php
require_once(dirname(__FILE__).'/include.php');

//サイドメニュー表示個所をglobal変数で制御
global $side_menu_mode;
if(isset($side_menu_mode)){
    $side_menu_mode_flg = $side_menu_mode;
}else{
    $side_menu_mode_flg = "";
}

//ログイン状態
if(!isset($login_status)){
    $login_status = chi_login_check();
}

//現在の会員数を取得
$member_num = get_data_num('shika_userbase');

//ピックアップ記事一覧を取得
$sql = "SELECT * ";
$fr_sql = "FROM (`blog_board` a LEFT JOIN `blog_board_category` b ON a.`system_blog_board_id` = b.`blog_board_category_board_id`) LEFT JOIN `blog_category` c ON b.`blog_board_category_category_id` = c.`system_blog_category_id` ";
$wh_sql = "WHERE a.`blog_board_allow_view` = ? AND a.`blog_board_flg3` <> ? AND a.`blog_board_state` = ? AND a.`blog_board_date` > ? ";
$param = array(1,1,1,time() - 60*60*24*30);
$or_sql = "ORDER BY a.`blog_board_score` DESC,a.`blog_board_date` DESC ";
$li_sql = "LIMIT 0,6";
$sql .= $fr_sql.$wh_sql.$or_sql.$li_sql;
$pickup_board_list = DB::query($sql,$param);

//人気記事一覧を取得
$sql = "SELECT * ";
$fr_sql = "FROM (`blog_board` a LEFT JOIN `blog_board_category` b ON a.`system_blog_board_id` = b.`blog_board_category_board_id`) LEFT JOIN `blog_category` c ON b.`blog_board_category_category_id` = c.`system_blog_category_id` ";
$wh_sql = "WHERE a.`blog_board_allow_view` = ? AND a.`blog_board_flg3` <> ? AND a.`blog_board_state` = ? ";
$param = array(1,1,1);

$not_in_sql = "";
if(count($pickup_board_list)>0){
    $not_in_sql = "AND a.`system_blog_board_id` NOT IN (";
    for($i=0;$i<count($pickup_board_list);$i++){
        if($i>0){ $not_in_sql .= ","; }
        $not_in_sql .= "?";
        $param[] =  $pickup_board_list[$i]['system_blog_board_id'];
    }
    $not_in_sql .= ") ";
}

$or_sql = "ORDER BY a.`blog_board_score` DESC,a.`blog_board_date` DESC ";
$li_sql = "LIMIT 0,6";
$sql .= $fr_sql.$wh_sql.$not_in_sql.$or_sql.$li_sql;
$best_board_list = DB::query($sql,$param);

?>
        <div class="search">

          <?php if($login_status): ?>
    <?php else: ?>
      <p>
      <a href='<?php echo DEFAULT_DIR_PATH; ?>../login.php?from=posiden/'>
      <img class="member" src="<?php echo DEFAULT_DIR_PATH; ?>images/login.png" alt="会員ログイン">
            </a>
            <!--<span style="font-size: 22px;font-weight: bold;"><a class="mainMapLink" href="http://dentaloupe.jp/posiden/../registration.php?from=posiden/" style="color: #000;">新規会員登録はこちら</a></span>-->
      </p>
    <?php endif; ?>

      <p class="form_text">現在の会員数&nbsp;<span class="font"><?php echo $member_num; ?></span>名</p>

      <form class="form_text" action='<?php echo DEFAULT_DIR_PATH;?>' method='GET' name="search4" id="search4">
        <dl class="search4">
          <dt>
                <?php if($keyword == ""): ?>
                <input type=text id="serarch_keyword" name='keyword' onfocus="if (this.value == '記事検索') this.value = ''; this.style.background = '#fff';  this.style.color = '#000';" onblur="if (this.value == ''){ this.value = '記事検索'; this.style.color = '#888'; this.style.background = '#fff'; }" value='記事検索' />
                <?php else: ?>
                <input type=text id="serarch_keyword" name='keyword' value='<?php foreach($keyword as $kwd){ echo htmlspecialchars($kwd); }; ?>' />
                <?php endif; ?>
          </dt>
        </dl>
      </form>

      <ul class="sns">

        <li>
            <a href='<?php echo DEFAULT_DIR_PATH; ?>rss/rss.xml' target="_blank"><i><rss class="fa fa-rss-square" aria-hidden="true"></i></a>
        </li>

        <li>
            <a href='http://www.facebook.com/pojiden/' target="_blank"> <i><fb class="fa fa-facebook-official" aria-hidden="true"></i></a>
        </li>

        <li>
            <a href='https://twitter.com/posiden_com' target="_blank"><i><tw class="fa fa-twitter-square" aria-hidden="true"></i></a>
        </li>
      </ul>

      <p class="aside_g"><?php include('ad/include3.php'); ?></p>
      <p class="aside_g"><?php include('ad/include4.php'); ?></p>
      <p class="aside_g"><?php include('ad/include7.php'); ?></p>
      <p class="aside_g"><?php include('ad/include8.php'); ?></p>
      <p class="aside_g"><?php include('ad/include5.php'); ?></p>
      <p class="aside_g"><?php include('ad/include6.php'); ?></p>
      <p class="aside_g"><?php include('ad/include9.php'); ?></p>
      <p class="aside_g"><?php include('ad/include10.php'); ?></p>
        </div>
    <!--カテゴリマップの表示開始-->
    <?php
    include('inc/category_map_generated.php');
    ?>
    <!--カテゴリマップの表示終了-->
<?php
require_once('include.php');
check_performance_start();

$login_status = chi_login_check();
check_performance('ログインチェック');

//GETパラメータの取得
$blog_category_alpha = isset($_GET['category']) ? $_GET['category'] : 0;    //カテゴリ絞り込み

/*ページャ機能拡張*/
//$system_blog_board_id = isset($_GET['board']) ? $_GET['board'] : "";  //個別記事表示の場合
$board = isset($_GET['board']) ? $_GET['board'] : "";   //個別記事表示の場合
$url_param = chi_url_parse($board);
$url_param['fb_disp_num'] = 1;
$url_param['board_disp_num'] = 15;
if ($url_param['news_disp_num'] == 0) {
    $url_param['news_disp_num'] = 20;
}
$system_blog_board_id = $url_param['board'];
/*ページャ機能拡張*/

$keyword = isset($_GET['keyword']) ? $_GET['keyword'] : ""; //キーワード検索の場合
$action = isset($_GET['action']) ? $_GET['action'] : ""; //ブックマーク処理
$board_start_num = isset($_GET['board_start_num']) ? $_GET['board_start_num'] : 0;
$board_num = isset($_GET['board_num']) ? $_GET['board_num'] : 9;

/*ページャ機能拡張*/
$board_start_num = $url_param['board_start_num'];
$board_num = $url_param['board_disp_num'];
/*ページャ機能拡張*/

check_performance('GETパラメータ取得');

$filename = basename($_SERVER["PHP_SELF"]);

//表示件数の計算
if ($system_blog_board_id == "") {
    $board_num_new = $board_num + 7;
    $board_last_num = $board_start_num + $board_num;
    check_performance('表示件数の計算');
}

//ブログ基本情報を取得
$blog_base = get_blog_base_kv(array('blog_base_alpha' => "posiden"));
check_performance('ブログ基本情報取得');

$title_disp = "";
$blog_board = "";
$access_time = isset($_SESSION['access_log_' . $system_blog_board_id]) ? $_SESSION['access_log_' . $system_blog_board_id] : 0;

// おすすめとして優先的に表示する最低日時をtimestamp型で取得(現在より60日前)
$minTimestamp = strtotime("-60 day");

//
/**
 * 人気記事取得SQL文を複数書きたくない為 多少強引にfunction化
 * @param number $index
 * @param number $type 0:件数取得,1:半年以内,2:半年を超える
 */
function createRecomSql($index = 0, $type = 0)
{
    if ($type == 0) {
        $sql  = "SELECT COUNT(*) as `count` ";
    } else {
        $sql  = "SELECT * ";
    }

    if ($type == 1) {
        $sql .= ", '0' as `flg` ";
    } else if ($type == 2) {
        $sql .= ", '1' as `flg` ";
    }

    $sql .= "FROM (`blog_board` a" . $index . " LEFT JOIN `blog_board_category` b" . $index . " ON a" . $index . ".`system_blog_board_id` = b" . $index . ".`blog_board_category_board_id`) ";
    $sql .= "LEFT JOIN `blog_category` c" . $index . " ON b" . $index . ".`blog_board_category_category_id` = c" . $index . ".`system_blog_category_id` ";
    $sql .= "WHERE a" . $index . ".`blog_board_allow_view` = ? ";
    $sql .= "AND a" . $index . ".`blog_board_flg3` <> ? ";
    $sql .= "AND a" . $index . ".`blog_board_state` = ? ";
    $sql .= "AND a" . $index . ".`blog_board_score` >= ? ";
    if ($type == 1) {
        $sql .= "AND a" . $index . ".`blog_board_date` >= ? ";
    } else if ($type == 2) {
        $sql .= "AND a" . $index . ".`blog_board_date` <= ? ";
    }
    return $sql;
}

// 人気記事一覧を取得(先に半年以内のデータを表示する)
$sql  = createRecomSql(0, 1);
$sql .= "UNION ";
$sql .= createRecomSql(1, 2);
$sql .= "ORDER BY `flg` ASC ";
$sql .= ", `blog_board_score` DESC ";
$sql .= ", `blog_board_date` DESC ";
$sql .= "LIMIT " . $board_start_num . "," . $board_num;
$param = array(
    1,
    1,
    1,
    20,
    $minTimestamp,
    1,
    1,
    1,
    20,
    $minTimestamp
);
$best_board_list = DB::query($sql, $param);

$param = array(
    1,
    1,
    1,
    20
);
$sql  = createRecomSql();

$cnt = DB::query($sql, $param);

$blog_board_num = isset($cnt[0]["count"]) ? $cnt[0]["count"] : 0;

global $disp_type;