一个小学口算出题的简单脚本kousuan.sh

 1 #!/bin/bash –
2 #=======================================================
3 #
4 # FILE: kousuan.sh
5 #
6 # USAGE: ./kousuan.sh
7 #
8 # DESCRIPTION: l 30 page i 50 per/page j1,j2 1-99+- j1,j2 1-9 */
9 # k 1-4 +-*/
10 # m 5 per line
11 # OPTIONS: —
12 # REQUIREMENTS: —
13 # BUGS: —
14 # NOTES: —
15 # AUTHOR: YOUR NAME (),
16 # COMPANY:
17 # CREATED: 2019年01月28日 12时48分11秒 CST
18 # REVISION: —
19 #=====================================================
20
21 set -o nounset # Treat unset variables as an error
22 #fucnion #
23 function rand3(){
24 min=$1
25 max=$(($2-$min+1))
26 num=$(cat /dev/urandom | head -n 10 | cksum | awk -F ‘ ‘ ‘{print $1}’)
27 echo $(($num%$max+$min))
28 }
29 function rand2(){
30 min=$1
31 max=$(($2-$min+1))
32 num=$(date +%s%N)
33 echo $(($num%$max+$min))
34 }
35
36 # rnd=$(rand 1 50)
37 # echo $rnd
38 function rand(){
39 min=$1
40 max=$(($2-$min+1))
41 echo $(($RANDOM%$max+$min))
42 }
43
44 #——–logic———–#
45 m=4
46 for l in $(seq 1 30)
47 do
48 n=0
49 j0=0
50 for i in $(seq 1 52)
51 do
52 k=$(rand 1 4)
53 # current rep / with *
54 if [ “$k” = “4” ] ; then
55 k=3
56 fi
57 case “$k” in
58 1) op=”+”;;
59 2) op=”-“;;
60 3) op=”X”;;
61 4) op=”/”;;
62 esac
63
64 if [ “$k” = “3” ] ; then
65 j1=$(rand3 1 9)
66 j2=$(rand2 2 9)
67 if [ “$j0” = “$j1” ] ; then
68 j1=$(rand 1 9)
69 fi
70 j0=$j1
71 else
72 j1=$(rand3 9 99)
73 j2=$(rand2 9 99)
74 if [ “$j0” = “$j1” ] ; then
75 j1=$(rand 1 9)
76 fi
77 j0=$j1
78 if [ “$k” = “2” ] ; then
79 if [ $j1 -lt $j2 ];then
80 t=$j1
81 j1=$j2
82 j2=$t
83 fi
84 elif [ “$k” = “1” ] ; then
85 if [ $[$j1 + $j2] -gt 100 ];then
86 if [ $j1 -gt 50 ];then
87 j1=$[$j1-50];
88 fi
89 if [ $j2 -gt 50 ];then
90 j2=$[$j2-50];
91 fi
92 # j1=$(($j1%10))
93 # j2=$(($j2%10))
94 fi
95 fi
96 fi
97 n=$[$n+1];
98 if [ “$n” = “$m” ] ; then
99 n=0;
100 echo -e “$j1 $op $j2 = \t “
101 echo “”
102 else
103
104 echo -e -n “$j1 $op $j2 = \t “
105 fi
106 done
107 echo “”
108 done
109

李海涛

关于李海涛

李海涛 lihaitao 山水 lihato 开源软件研究与服务
此条目发表在知识积累分类目录。将固定链接加入收藏夹。