golang中的非均匀分布随机

Non-uniform distribution random in golang

引自league of legends:

The probability of a critical strike changes dynamically based on how many times the attack critically strikes. If an attack does not critically strike over multiple attempts, the probability will progressively increase for future attempts—this can occur vice versa, where multiple successful critical strikes will cause the probability to progressively decrease for future attempts.

如果我没理解错的话,一个事件出现的几率会逐渐受到之前时间的影响,即non-uniform distribution随机化,对吧? golangmath/rand有这样的随机算法吗?如果没有,我们如何实施?

鉴于 rand.Float32()rand.Float64(),这似乎很容易实现。没有看到你的代码,很难给出很多代码。

您可以重复采样统一的浮点数并与不同的成功概率进行比较。这个概率在未命中时上升,在命中时下降。

例如:

func did_crit_hit(prob_success *float64) bool {
    p := *prob_success
    hit := rand.Float64() < p
    if hit {
        p = math.Max(0, p - 0.1)
    } else {
        p = math.Min(1, p + 0.1)
    }
    *prob_success = p
    return hit
}

您可能想要做一些比仅按固定增量更改更复杂的事情,但希望这能给您一个想法。