The first thing to know is how to play color ball: 6 red balls (1~33) and a Blue ball (1~16) to choose a so-called 6+1
To generate 6 random numbers between 1~33 and cannot be equal, this is key if you use traditional judging methods (the first with the second ...). The second and third ratio ...), is bound to code will be very long, my idea is: use ${random}% 33 +1, put the 6 red balls in an array of red, using: For J in "${red[@]}";d o echo $J;d one) |sort |uni Q-d the way to judge if there is no duplicate value
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/54/wKioL1fdfbfB_uIVAACEcWZ7j6I614.png "title=" 99.PNG "alt=" Wkiol1fdfbfb_uivaacecwz7j6i614.png "/>
Execution effect: 10 Note For example:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/87/56/wKiom1fdfhmAtP4RAAA4UvN2A0U577.png "title=" 99.PNG "alt=" Wkiom1fdfhmatp4raaa4uvn2a0u577.png "/>
Text
#!/bin/bash
#Author: Wangergui email:[email protected] date:2016-09-17
#Release 1.0
#Function: Shuang se Qiu
Declare-a RED
Read-t 10-p "Please input a number:" NUM
Str= ' echo ${num} |sed ' sn^.*[[:d igit:]] $NNg "
[-Z "${str}"] | | Exit 2
For I in ' seq ${num} ';d o
While True;do
Red= ($ ($RANDOM% + 1)) $ (($RANDOM% + 1)) $ (($RANDOM% + 1)) $ (($RANDOM% + 1)) $ (($RANDOM% + 1)) $ (($RANDOM% 33 + 1)))
blue=$ (($RANDOM% 16 + 1))
String= ' (for J in "${red[@]}";d o echo $J;d one) |sort |uniq-d '
if [[-Z ' ${string} ']];then
Echo-e "\e[40;31;1m ${red[@]}\e[0m | | \e[40;34;1m ${blue}\e[0m "&& break
Fi
Done
Done
This article from the "Linux-related technology" blog, declined to reprint!
Color Ball of shell scripts