用php和shell自动生成彩票号码的源码

2019年10月21日

这是一个以前我写的彩票号码自动生成的代码解释,是用Linux下的shell脚本和php自动生成的。其实原理非常简单,只是利用了shell和php的一些内置变量和循环操作还有随机数来实现的。像七星彩就是利用了随机数和循环来实现,而大乐透和双色球是利用了数组循环来截取随机的数字实现的。然后再通过排序和过滤就可以了。

演示地址:http://jiayu.mybabya.com/chai.php

Shell源码

# !/bin/bash
. /etc/profile
###############################################################################################################################################################################################
#
# This is a lottery number automatic generation tool
# Autor: RucLinux
# Web: http://www.myzhenai.com.cn/ http://www.myzhenai.com/ http://www.haikou-china.com/ http://jiayu.mybabya.com/ http://www.0898-shop.com/
#
###############################################################################################################################################################################################

###########################################################################################################
function qixingchai() {
  for i in 1 2 3 4 5
  do
  a=`shuf -i 0-9 -n 7`
  c=`echo ${a} | sed 'N;s/\n//g'`
  index=0
  str=""
  for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done
  for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done
  for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done
  for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done
  for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done
  for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done
  for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done
  for i in {1..42}; do str="$str${arr[$RANDOM%$index]}"; done
  s=`echo $str |cut -c1-7`
  echo "七星彩号码: <font color=\"#fb0b0b\">${c}</font>" >> chai.log
  echo "七星彩号码: <font color=\"#fb0b0b\">${s:0:1} ${s:1:1} ${s:2:1} ${s:3:1} ${s:4:1} ${s:5:1} ${s:6:1}</font>" >> chai.log
  done
  echo "<hr />" >> chai.log
}
###########################################################################################################

###########################################################################################################
function daletao() {
  for i in 1 2 3 4 5 6 7 8 9 10
  do
  a=`shuf -i 1-36 -n 5`
  b=`shuf -i 1-12 -n 2`
  c=`echo ${a} | sed 'N;s/\n//g' | tr -s " " "\n" | sort -n | tr -s "\n" " "; echo`
  d=`echo ${b} | sed 'N;s/\n//g' | tr -s " " "\n" | sort -n | tr -s "\n" " "; echo`
  echo "大乐透号码: <font color=\"#fb0b0b\">$c</font> <font color=\"#0b0aec\">$d</font>" >> chai.log
  done
  echo "<hr />" >> chai.log
}
###########################################################################################################

###########################################################################################################
function shuangseqiu() {
  for i in 1 2 3 4 5 6 7 8 9 10
  do
  a=`shuf -i 1-33 -n 6`
  b=`shuf -i 1-16 -n 1`
  c=`echo ${a}|sed 'N;s/\n//g' | tr -s " " "\n" | sort -n | tr -s "\n" " "; echo`
  d=`echo ${b}|sed 'N;s/\n//g' | tr -s " " "\n" | sort -n | tr -s "\n" " "; echo`
  echo "双色球号码: <font color=\"#fb0b0b\">$c</font> <font color=\"#0b0aec\">$d</font>" >> chai.log
  done
  echo "<hr />" >> chai.log
}
###########################################################################################################

###########################################################################################################
gener() {
  rm -rf chai.log
  d=`date +%w`
  q="250"
  if [[ $q =~ "${d}" ]]; then
  qixingchai
  fi
  a="136"
  if [[ $a =~ "${d}" ]]; then
  daletao
  fi
  h="240"
  if [[ $h =~ "${d}" ]]; then
  shuangseqiu
  fi
  chown -R apache:apache chai.log
  chmod 755 chai.log
}
###########################################################################################################

#This is the documentation help
###########################################################################################################
Open_help() (
echo 'This is a lottery number automatic generation tool'
echo ``
echo '-q This is the Seven Star Lottery number generation'
echo '-d This is a lottery lottery number automatically generated'
echo '-s This is a two-tone ball lottery number automatically generated'
echo '-g This is the automatic selection option'
echo '-h This is the documentation'
)
###########################################################################################################
par=$1
[ -z $1 ] && action='-h'
case "$par" in
    -h)
    Open_help
    ;;
    -q)
    qixingchai
    ;;
    -d)
    daletao
    ;;
    -s)
    shuangseqiu
    ;;
    -g)
    gener
    ;;
    *)
    echo "Arguments error! [${par}]"
    echo "Usage: `basename $0` {-h|-q|-d|-s|-g"
    ;;
esac

PHP源码

< !DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta charset="UTF-8"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>七星彩 大乐透 双色球 随机号码工具</title>
    <meta name="description" content="七星彩 大乐透 双色球 随机号码工具"/>
    <meta name="keywords" content="七星彩 大乐透 双色球 随机号码工具"/>
    < ?php

    function read_on($o)
    {
        $x = 1;
        while ($x <= $o) {
            $ad = array();
            $ad[] = $x;
            $x++;
            echo $ad[$x];
        }
        return $ad;
    }

    function fenge($con)
    {
        $str = str_split($con);
        $i = join(" ", $str);
        return $i;
    }

    function qixingchai()
    {
        $x = 1;
        while ($x <= 10) {
            $id = mt_rand();
            $a = strlen($id);
            if ($a > 7) {
                $ip = fenge(substr($id, 0, 7));
                $d = "七星彩号码: <font color=\"#fb0b0b\">$ip</font>\n";
                echo "<tt><ul><li>$d</li></ul></tt>";
                $x++;
            }
        }
        echo "<hr />";
    }

    function pailiew()
    {
        $px = 1;
        while ($px < = 10) {
            $pid = mt_rand();
            $pa = strlen($pid);
            if ($pa > 5) {
                $pip = fenge(substr($pid, 0, 5));
                $pd = "排列5号码: <font color=\"#fb0b0b\">$pip</font>\n";
                echo "<tt><ul><li>$pd</li></ul></tt>";
                $px++;
            }
        }
        echo "<hr />";
    }

    function pailies()
    {
        $vx = 1;
        while ($vx < = 10) {
            $vid = mt_rand();
            $va = strlen($vid);
            if ($va > 3) {
                $vip = fenge(substr($vid, 0, 3));
                $vd = "排列3号码: <font color=\"#fb0b0b\">$vip</font>\n";
                echo "<tt><ul><li>$vd</li></ul></tt>";
                $vx++;
            }
        }
        echo "<hr />";
    }

    function daletao()
    {
        $x = 1;
        while ($x < = 10) {
            $arr = range(1, 35);

            $brr = range(1, 12);
            shuffle($arr);
            shuffle($brr);
            sort($arr);
            sort($brr);
            $a = array_rand($arr, 5);
            $char = implode(" ", $a);
            $b = array_rand($brr, 2);
            $bhar = implode(" ", $b);
            $d = "大乐透号码: <font color=\"#fb0b0b\">$char <font color=\"#0b0aec\">$bhar</font>\n";
            echo "<tt><ul><li>$d</li></ul></tt>";
            $x++;
        }
        echo "<hr />";
    }

    function shuangseqiu()
    {
        $x = 1;
        while ($x < = 10) {
            $arr = range(1, 33);
            $brr = range(1, 16);
            shuffle($arr);
            shuffle($brr);
            $a = array_rand($arr, 6);
            $b = array_rand($brr, 1);
            sort($a);
            $char = implode(" ", $a);
            #$bhar = implode(" ",$b);
            $d = "双色球号码: <font color=\"#fb0b0b\">$char <font color=\"#0b0aec\">$b</font>\n";
            echo "<tt><ul><li>$d</li></ul></tt>";
            $x++;
        }
        echo "<hr />";
    }


    function gener()
    {
        $r = date("w");
        $tr = strpos("2450", $r);
        if ($tr !== false) {
            echo "<b>今天是七星彩或双色球的开奖日期</b>\n";
        }
        $tr = strpos("136", $r);
        if ($tr !== false) {
            echo "<b>今天是大乐透的开奖日期</b>\n";
        }
        $tr = strpos("250", $r);
        if ($tr !== false) {
            echo pailies();
            echo pailiew();
            echo qixingchai();
        }
        $tr = strpos("240", $r);
        if ($tr !== false) {
            echo pailies();
            echo pailiew();
            echo shuangseqiu();
        }
        $tr = strpos("136", $r);
        if ($tr !== false) {
            echo pailies();
            echo pailiew();
            echo daletao();
        }
    }

    ?>
    < ?php
    function get_line($file)
    {
        if (file_exists($file)) {
            $fp = fopen($file, 'r');
            $i = 0;
            while (!feof($fp)) {
                $i++;
                $dp = fgets($fp);
                if ($dp == "" || strpos($dp, "<hr />") !== false) {
                    echo $dp;
                } else {
                    echo "<tt><ul><li>$dp</li></ul></tt>";
                }
            }
        }
        fclose($fp);
    }

    function player($music)
    {
        echo "<audio src=\"$music\" loop=\"loop\" autoplay=\"autoplay\"></audio>";
    }



    ?>
</head>
<body>
<div>
    <form>
        <fieldset style="width:600px;margin:0px auto">
            <legend align="center"><b><h1>七星彩 大乐透 双色球 随机号码工具</h1></b></legend>
            <hr />
            <div align="center;margin:200px auto">
            < ?php echo gener(); ?>
            < ?php echo get_line("lotk.log"); ?>
            < ?php echo music_player(); ?>
            </div>
            <div style=" text-align:center"><a style=" font-size:18px; text-decoration:none"
                                               href="http://jiayu.mybabya.com">JiaYuBlog</a>
            </div>
            <div style=" text-align:center"><a style=" font-size:18px; text-decoration:none"
                                               href="http://jiayu.mybabya.com">
                    开发作者:周经业</a> &&
                <script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
                    document.write(unescape("%3Cspan id='cnzz_stat_icon_4938298'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s9.cnzz.com/stat.php%3Fid%3D4938298%26show%3Dpic' type='text/javascript'%3E%3C/script%3E"));</script>
            </div>
        </fieldset>
    </form>
</div>
</body>
</html>


sicnature ---------------------------------------------------------------------
Your current IP address is: 3.226.254.115
Your IP address location: 美国弗吉尼亚阿什本
Your IP address country and region: 美国 美国
Your current browser is:
Your current system is:
Original content, please indicate the source:
同福客栈论坛 | 海南仙岛海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source http://www.myzhenai.com.cn/post/2903.html

没有评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注