blog/go/double_ball/main.go

68 lines
1.1 KiB
Go

package main
import (
"flag"
"fmt"
"math/rand"
"sort"
"time"
)
const (
RedMax = 33
BlueMax = 16
)
func randRate(){
rand.Seed(time.Now().UnixNano())
rate := rand.Intn(100) + 1
fmt.Printf("\t (中奖概率%d%%)", rate)
}
func randBall(max int)int{
rand.Seed(time.Now().UnixNano())
return rand.Intn(max) + 1
}
func isIn(list []int, item int )bool{
for _, i := range list{
if i == item {
return true
}
}
return false
}
func randDoubleBall(){
balls := []int{}
for i := 0; i < 6;{
ball := randBall(RedMax)
if isIn(balls, ball) {
continue
}
i++
balls = append(balls, ball)
}
sort.Ints(balls)
blueball := randBall(BlueMax)
for _, ball := range balls {
fmt.Printf("\033[1;31;40m%d\033[0m \t", ball)
}
fmt.Printf("\033[1;34;40m%d\033[0m \t", blueball)
randRate()
fmt.Println("")
}
func main(){
var groups int
flag.IntVar(&groups, "g", 1, "注数")
flag.Parse()
if groups < 0 {
groups = 1
}
fmt.Printf("为您选取了 %d 注随机双色球,祝君中奖!\n", groups)
for i := 0; i < groups; i++ {
randDoubleBall()
}
}