Skip to content

Commit

Permalink
用结果数组的长度作为随机数最大值、防止越界
Browse files Browse the repository at this point in the history
  • Loading branch information
hutiance committed Sep 30, 2021
1 parent e667fb8 commit 217fa62
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plugin_image_finder/keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func init() {
keyword := ctx.State["regex_matched"].([]string)[1]
soutujson := soutuapi(keyword)
pom1 := "https://i.pixiv.cat"
rannum := randint()
rannum := randint(len(soutujson.Illusts))
pom2 := soutujson.Illusts[rannum].ImageUrls.Large[19:]
ctx.SendChain(message.Image(pom1 + pom2))
})
Expand Down Expand Up @@ -103,7 +103,7 @@ func soutuapi(keyword string) *resultjson {
}

// randint 从json里的30条数据中随机获取一条返回
func randint() int {
func randint(len int) int {
rand.Seed(time.Now().UnixNano())
return rand.Intn(30)
return rand.Intn(len)
}

0 comments on commit 217fa62

Please sign in to comment.