选择具有不同概率的三个数字

时间:2017-07-27 15:53:25

标签: imacros

如何设置此代码(即2个数字)以在三个数字中选择" 0.5" ," 0.75"和" 1"并为他们指定一个被选中的机会,例如20%" 0.5" ,50%" 0.75"和30%" 1" ?

SET !VAR1 EVAL("Math.random() > 0.6 ? '1' : '0.75'")
TAG POS=1 TYPE=SELECT ATTR=ID:t_score CONTENT=%{{!VAR1}}

1 个答案:

答案 0 :(得分:0)

以下内容应该有效:

Math.random() < 0.2 ? '0.5' : (Math.random() < 0.5/(0.5 + 0.3) ? '0.75' : '1')

或者您也可以使用以下逻辑(但我不知道如何将其添加到iMacros中):

var rand = Math.random();
rand < 0.2 ? '0.5' : (rand < 0.2 + 0.5 ? '0.75' : '1')