diff --git a/main.go b/main.go index 1296a0a..36b27a0 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,8 @@ import ( "github.com/astaxie/beego" "github.com/astaxie/beego/logs" "github.com/astaxie/beego/plugins/cors" + "math/rand" + "time" ) func main() { @@ -42,6 +44,8 @@ func Init() bool { svconst.AppName = beego.AppConfig.String("appname") + rand.NewSource(time.Now().UnixNano()) + svlog.Init() if beego.BConfig.RunMode != "dev" { diff --git a/service/roomrank/dto-room.go b/service/roomrank/dto-room.go index d40fce7..0f91a8b 100644 --- a/service/roomrank/dto-room.go +++ b/service/roomrank/dto-room.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "github.com/samber/lo" + "math/rand" ) // Room 房间排行持久数据 @@ -46,7 +47,7 @@ type RoomPlayer struct { func NewRoomRobot(robotConfigId int, userType int) *RoomPlayer { d := &RoomPlayer{ - Uid: 0, + Uid: rand.Int63(), Score: 0, JoinTime: lxtime.NowUninx(), UserType: userType, diff --git a/service/roomrank/room.go b/service/roomrank/room.go index f5aab5b..2e1ac39 100644 --- a/service/roomrank/room.go +++ b/service/roomrank/room.go @@ -6,7 +6,7 @@ import ( "apigame/util/util-lx/lxalilog" "apigame/util/util-lx/lxtime" "math" - "math/rand/v2" + "math/rand" "sort" ) @@ -270,7 +270,7 @@ func GetRobotScoreCurrent(config *confroomrank.ActivityConfig, confRobot *confro } score := (float64(confRobot.TotalScore-confRobot.MinScore) * - float64(100-confRobot.TotalRate+rand.IntN(confRobot.TotalRate*2)) / 100) * percent / 100 + float64(100-confRobot.TotalRate+rand.Intn(confRobot.TotalRate*2)) / 100) * percent / 100 result := int64(confRobot.MinScore) + int64(math.Ceil(score)) if result < int64(confRobot.MinScore) { result = int64(confRobot.MinScore) @@ -281,7 +281,7 @@ func GetRobotScoreCurrent(config *confroomrank.ActivityConfig, confRobot *confro // GetRobotScoreMax 从机器人配置里得到最高分 func GetRobotScoreMax(confRobot *confroomrank.RobotConfig) int64 { score := float64(confRobot.TotalScore-confRobot.MinScore) * - float64(100-confRobot.TotalRate+rand.IntN(confRobot.TotalRate*2)) / float64(100) + float64(100-confRobot.TotalRate+rand.Intn(confRobot.TotalRate*2)) / float64(100) result := int64(confRobot.MinScore) + int64(math.Ceil(score)) if result < int64(confRobot.MinScore) { result = int64(confRobot.MinScore) diff --git a/util/utmap/map.go b/util/utmap/map.go index fff0f1d..c617fd2 100644 --- a/util/utmap/map.go +++ b/util/utmap/map.go @@ -1,8 +1,8 @@ package utmap import ( + "apigame/util/uttype" "math/rand" - "venus/util/uttype" ) // Keys Keys切片 -- libgit2 0.21.0