我有一个随机选择选项的规则:
.RuleFor(c=>field, x=>x.PickRandom("Option1", "Option2", "Option3", "Option4"))
Run Code Online (Sandbox Code Playgroud)
使用默认值,我可以更改其中一项的概率。我想设置所有四个项目的概率。选项 1 的概率为 50%,选项 2 的概率为 30%,选项 3 的概率为 15%,选项 4 的概率为 5%。
我想使用 WeightedRandom:
.RuleFor(c=>field, x=>PickWeightedRandom(valueArray, weightArray)
Run Code Online (Sandbox Code Playgroud)
没有像 PickWeightedRandom 这样的方法,但 WeightedRandom 是 Randomizer 类中的一个方法。如何让 WeightedRandom 发挥作用?
编辑:也许是一种扩展方法?