Skip to content

[refactor][P3] mathx 包级随机源双轨制 + 单锁竞争 #386

Closed

Description

@zy84338719

来源:2026-11-11 全矩阵深度代码审查(6 路并行扫描约 24 万行 Go)。判定已复核;行号基于 2026-11-11 的 main,动手前请核对现场。
归档索引:#372(本仓重构 backlog)

位置

pkg/mathx/math.go:14-17、29-31、246(二轮审查发现,已人工复核)

证据

var (
    rng   = rand.New(rand.NewSource(time.Now().UnixNano()))
    rngMu sync.Mutex
)
// RandIntn: rngMu.Lock(); v := rng.Intn(maxInt); rngMu.Unlock()
// 而 RangeRandFloat64(:246) 直接用全局 rand.Float64()(另一套源)

Probability→RandIntn 的概率路由并发调用时全部在 rngMu 上排队(同 logx ShouldLog 每日志取锁的形态,logx#171 已单开);且两套随机源行为不一致。

建议

统一迁到 math/rand/v2(无锁、每 goroutine 独立)或直接用全局 rand(v1 全局自带锁/v2 无锁),删掉手搓 rng+rngMu;顺带消除两套随机源行为不一致。

Activity

  1. moved this from Todo to In Progress in oekit Issue 大盘on Nov 12, 2026
  2. added a commit that references this issue on Nov 12, 2026
  3. moved this from In Progress to Done in oekit Issue 大盘on Nov 12, 2026
  4. zy84338719 commented on Nov 12, 2026

    @zy84338719
    ContributorAuthor

    已合入修复 ✅(无 SemVer 发布:本次改动不发版本)

    变更内容

    mathx 随机源统一迁 math/rand/v2,删手搓 rng+rngMu 单锁,双轨制消除

    合入:PR #423(https://github.com/oekit/pkg/pull/423),merge commit 53135ccf,2026-11-12T17:13:18Z

    CI:link ✅ / Lint & Test / Test ✅ / Lint & Test / Lint ✅ / Zero Third-Party Deps ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactor重构机会(代码审查产出)

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions