Skip to content

Instantly share code, notes, and snippets.

@xuzhenglun
Last active May 24, 2016 15:41
Show Gist options
  • Save xuzhenglun/41632144fcc486115a1169bd52e982d7 to your computer and use it in GitHub Desktop.
Save xuzhenglun/41632144fcc486115a1169bd52e982d7 to your computer and use it in GitHub Desktop.
随机数成绩生成器,钦定一下
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
A, detaila := 钦定一下(65, 75, []int{10, 15, 15, 10, 10, 10, 5, 20, 5})
B, detailb := 钦定一下(65, 75, []int{15, 20, 20, 15, 15, 15})
C, detailc := 钦定一下(65, 75, []int{10, 15, 15, 10, 10, 10, 30})
fmt.Println(A, detaila)
fmt.Println(B, detailb)
fmt.Println(C, detailc)
fmt.Println("Ava:", float32(A+B+C)/3)
}
func letSeeTheGodsWill(req []int) (sum int, will []int) {
rand.Seed(time.Now().UnixNano())
will = make([]int, len(req))
for i, v := range req {
will[i] = rand.Intn(v/2) + v/2
}
for _, v := range will {
sum += v
}
return
}
func 钦定一下(min, max int, req []int) (int, []int) {
for {
if sum, will := letSeeTheGodsWill(req); sum < max && sum > min {
return sum, will
} else {
time.Sleep(1)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment