🎨 🔥 统一 seed

This commit is contained in:
fumiama 2022-02-18 20:20:25 +08:00
parent 3838d74cb8
commit bd6925f2f1
7 changed files with 8 additions and 17 deletions

View File

@ -3,8 +3,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"math/rand"
"os" "os"
"strings" "strings"
"time"
// ---------以下插件均可通过前面加 // 注释,注释后停用并不加载插件--------- // // ---------以下插件均可通过前面加 // 注释,注释后停用并不加载插件--------- //
// ----------------------插件优先级按顺序从高到低---------------------- // // ----------------------插件优先级按顺序从高到低---------------------- //
@ -220,6 +222,7 @@ func getKanban() string {
func main() { func main() {
order.Wait() order.Wait()
printBanner() printBanner()
rand.Seed(time.Now().UnixNano()) // 全局 seed其他插件无需再 seed
// 帮助 // 帮助
zero.OnFullMatchGroup([]string{"/help", ".help", "菜单"}, zero.OnlyToMe).SetBlock(true). zero.OnFullMatchGroup([]string{"/help", ".help", "菜单"}, zero.OnlyToMe).SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {

View File

@ -4,7 +4,6 @@ package aiwife
import ( import (
"fmt" "fmt"
"math/rand" "math/rand"
"time"
control "github.com/FloatTech/zbputils/control" control "github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext" "github.com/FloatTech/zbputils/ctxext"
@ -19,7 +18,6 @@ const (
) )
func init() { // 插件主体 func init() { // 插件主体
rand.Seed(time.Now().UnixNano())
control.Register("aiwife", order.AcquirePrio(), &control.Options{ control.Register("aiwife", order.AcquirePrio(), &control.Options{
DisableOnDefault: false, DisableOnDefault: false,
Help: "AIWife\n" + Help: "AIWife\n" +

View File

@ -2,9 +2,6 @@
package diana package diana
import ( import (
"math/rand"
"time"
zero "github.com/wdvxdr1123/ZeroBot" zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message" "github.com/wdvxdr1123/ZeroBot/message"
@ -36,7 +33,6 @@ func init() {
// 随机发送一篇上面的小作文 // 随机发送一篇上面的小作文
engine.OnFullMatch("小作文").SetBlock(true). engine.OnFullMatch("小作文").SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
rand.Seed(time.Now().UnixNano())
// 绕过第一行发病 // 绕过第一行发病
ctx.SendChain(message.Text(data.RandText())) ctx.SendChain(message.Text(data.RandText()))
}) })

View File

@ -188,8 +188,8 @@ func randimage(path string, seed int64) (im image.Image, index int, err error) {
} }
defer reader.Close() defer reader.Close()
rand.Seed(seed) r := rand.New(rand.NewSource(seed))
index = rand.Intn(len(reader.File)) index = r.Intn(len(reader.File))
file := reader.File[index] file := reader.File[index]
f, err := file.Open() f, err := file.Open()
if err != nil { if err != nil {
@ -206,9 +206,9 @@ func randimage(path string, seed int64) (im image.Image, index int, err error) {
// @param seed 随机数种子 // @param seed 随机数种子
// @return 签名 & 签文 & 错误信息 // @return 签名 & 签文 & 错误信息
func randtext(seed int64) (string, string) { func randtext(seed int64) (string, string) {
rand.Seed(seed) r := rand.New(rand.NewSource(seed))
r := rand.Intn(len(omikujis)) i := r.Intn(len(omikujis))
return omikujis[r]["title"], omikujis[r]["content"] return omikujis[i]["title"], omikujis[i]["content"]
} }
// @function draw 绘制运势图 // @function draw 绘制运势图

View File

@ -2,11 +2,9 @@
package gif package gif
import ( import (
"math/rand"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
"time"
control "github.com/FloatTech/zbputils/control" control "github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext" "github.com/FloatTech/zbputils/ctxext"
@ -24,7 +22,6 @@ var (
) )
func init() { // 插件主体 func init() { // 插件主体
rand.Seed(time.Now().UnixNano()) // 设置种子
en := control.Register("gif", order.AcquirePrio(), &control.Options{ en := control.Register("gif", order.AcquirePrio(), &control.Options{
DisableOnDefault: false, DisableOnDefault: false,
Help: "制图\n- " + strings.Join(cmds, "\n- "), Help: "制图\n- " + strings.Join(cmds, "\n- "),

View File

@ -342,7 +342,6 @@ func init() { // 插件主体
return temp[i].Get("last_sent_time").Int() < temp[j].Get("last_sent_time").Int() return temp[i].Get("last_sent_time").Int() < temp[j].Get("last_sent_time").Int()
}) })
temp = temp[math.Max(0, len(temp)-10):] temp = temp[math.Max(0, len(temp)-10):]
rand.Seed(time.Now().UnixNano())
who := temp[rand.Intn(len(temp))] who := temp[rand.Intn(len(temp))]
if who.Get("user_id").Int() == ctx.Event.SelfID { if who.Get("user_id").Int() == ctx.Event.SelfID {
ctx.SendChain(message.Text("幸运儿居然是我自己")) ctx.SendChain(message.Text("幸运儿居然是我自己"))

View File

@ -8,7 +8,6 @@ import (
"os" "os"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/FloatTech/zbputils/web" "github.com/FloatTech/zbputils/web"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
@ -160,7 +159,6 @@ func (vdb *VtbDB) GetThirdCategory(firstIndex, secondIndex, thirdIndex int) Thir
// RandomVtb ... // RandomVtb ...
func (vdb *VtbDB) RandomVtb() ThirdCategory { func (vdb *VtbDB) RandomVtb() ThirdCategory {
db := (*gorm.DB)(vdb) db := (*gorm.DB)(vdb)
rand.Seed(time.Now().UnixNano())
var count int var count int
var tc ThirdCategory var tc ThirdCategory
db.Model(&ThirdCategory{}).Count(&count).Offset(rand.Intn(count)).Take(&tc) db.Model(&ThirdCategory{}).Count(&count).Offset(rand.Intn(count)).Take(&tc)