generated from bing/readnotes
95 lines
1.4 KiB
Go
95 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"math/rand"
|
|
"sort"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
RedMax = 33
|
|
BlueMax = 16
|
|
)
|
|
|
|
type ball struct{
|
|
B int
|
|
R []int
|
|
Rate int
|
|
}
|
|
|
|
func (b ball)display(){
|
|
for _, r := range b.R {
|
|
fmt.Printf("\033[1;31;40m%d\033[0m \t", r)
|
|
}
|
|
fmt.Printf("\033[1;34;40m%d\033[0m \t", b.B)
|
|
fmt.Printf("\t (中奖概率%d%%)\n", b.Rate)
|
|
}
|
|
|
|
func randRate() int {
|
|
src := rand.NewSource(time.Now().UnixNano())
|
|
rd := rand.New(src)
|
|
rate := rd.Intn(100) + 1
|
|
return rate
|
|
}
|
|
|
|
func randBall(max int) int {
|
|
src := rand.NewSource(time.Now().UnixNano())
|
|
rd := rand.New(src)
|
|
return rd.Intn(max) + 1
|
|
}
|
|
|
|
func isIn(list []int, item int) bool {
|
|
for _, i := range list {
|
|
if i == item {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func randDoubleBall()ball{
|
|
b := ball{}
|
|
for i := 0; i < 6; {
|
|
r := randBall(RedMax)
|
|
if isIn(b.R, r) {
|
|
continue
|
|
}
|
|
i++
|
|
b.R = append(b.R, r)
|
|
}
|
|
sort.Ints(b.R)
|
|
b.B = randBall(BlueMax)
|
|
b.Rate = randRate()
|
|
return b
|
|
}
|
|
|
|
func main() {
|
|
var groups int
|
|
var zhong bool
|
|
flag.IntVar(&groups, "g", 0, "注数")
|
|
flag.BoolVar(&zhong, "z", true, "必中")
|
|
flag.Parse()
|
|
if groups < 1 {
|
|
groups = 1
|
|
}else{
|
|
zhong = false
|
|
}
|
|
if zhong {
|
|
for {
|
|
b := randDoubleBall()
|
|
if b.Rate == 100 {
|
|
b.display()
|
|
break
|
|
}
|
|
}
|
|
return
|
|
}
|
|
fmt.Printf("为您选取了 %d 注随机双色球,祝君中奖!\n", groups)
|
|
for i := 0; i < groups; i++ {
|
|
b:=randDoubleBall()
|
|
b.display()
|
|
}
|
|
}
|