Color Ball of shell scripts

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.