huangkun
1 year ago
8 changed files with 101 additions and 3 deletions
@ -0,0 +1,13 @@ |
|||
FROM golang:1.19 as builder |
|||
WORKDIR /workdir |
|||
ADD go.mod go.mod |
|||
ADD go.sum go.sum |
|||
ENV GOPROXY=https://goproxy.cn,direct GO111MODULE=on |
|||
RUN go mod download |
|||
ADD main.go main.go |
|||
ADD pkg pkg |
|||
RUN GOOS=linux GOARCH=amd64 go build -o /appname main.go |
|||
|
|||
FROM scratch |
|||
COPY --from=builder /workdir/appname / |
|||
ENTRYPOINT [ "/appname" ] |
@ -0,0 +1,68 @@ |
|||
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() |
|||
} |
|||
} |
@ -0,0 +1 @@ |
|||
package main |
Binary file not shown.
Loading…
Reference in new issue