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

2019年10月21日

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

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

Shell源码

# !/bin/bash
. /etc/profile
###############################################################################################################################################################################################
#
# This is a lottery number automatic generation tool
# Autor: RucLinux
# Web: https://www.myzhenai.com.cn/ https://www.myzhenai.com/ https://www.haikou-china.com/ https://jiayu.mybabya.com/ https://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 "七星彩号码: ${c}" >> chai.log
  echo "七星彩号码: ${s:0:1} ${s:1:1} ${s:2:1} ${s:3:1} ${s:4:1} ${s:5:1} ${s:6:1}" >> chai.log
  done
  echo "
" >> 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 "大乐透号码: $c $d" >> chai.log done echo "
" >> 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 "双色球号码: $c $d" >> chai.log done echo "
" >> 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>


    
    
    
    七星彩 大乐透 双色球 随机号码工具
    
    
    < ?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 = "七星彩号码: $ip\n";
                echo "
  • $d
"; $x++; } } echo "
"; } function pailiew() { $px = 1; while ($px < = 10) { $pid = mt_rand(); $pa = strlen($pid); if ($pa > 5) { $pip = fenge(substr($pid, 0, 5)); $pd = "排列5号码: $pip\n"; echo "
  • $pd
"; $px++; } } echo "
"; } function pailies() { $vx = 1; while ($vx < = 10) { $vid = mt_rand(); $va = strlen($vid); if ($va > 3) { $vip = fenge(substr($vid, 0, 3)); $vd = "排列3号码: $vip\n"; echo "
  • $vd
"; $vx++; } } echo "
"; } 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 = "大乐透号码: $char $bhar\n"; echo "
  • $d
"; $x++; } echo "
"; } 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 = "双色球号码: $char $b\n"; echo "
  • $d
"; $x++; } echo "
"; } function gener() { $r = date("w"); $tr = strpos("2450", $r); if ($tr !== false) { echo "今天是七星彩或双色球的开奖日期\n"; } $tr = strpos("136", $r); if ($tr !== false) { echo "今天是大乐透的开奖日期\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, "
") !== false) { echo $dp; } else { echo "
  • $dp
"; } } } fclose($fp); } function player($music) { echo ""; } ?>

七星彩 大乐透 双色球 随机号码工具


< ?php echo gener(); ?> < ?php echo get_line("lotk.log"); ?> < ?php echo music_player(); ?>
开发作者:周经业 &&

 


sicnature ---------------------------------------------------------------------
I P 地 址: 18.191.216.163
区 域 位 置: 美国俄亥俄
系 统 信 息: 美国
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source http://myzhenai.com/post/2903.html

1 评论

  • 海南胡说 2020年01月12日在12:16 上午

    #vi /etc/crontab
    #vi /var/spool/cron/root
    添加一个定时任务,设置每天晚上的零点正执行脚本。在定时里添加以下内容。
    0 0 * * * root /home/lotk.sh -g
    #service crond restart
    重启定时器

回复 海南胡说 取消回复

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