代码之家  ›  专栏  ›  技术社区  ›  Amir Hossein

从三个不同概率的数字中选择

  •  -1
  • Amir Hossein  · 技术社区  · 9 年前

    SET !VAR1 EVAL("Math.random() > 0.6 ? '1' : '0.75'")
    TAG POS=1 TYPE=SELECT ATTR=ID:t_score CONTENT=%{{!VAR1}}
    
    1 回复  |  直到 9 年前
        1
  •  0
  •   Stephan    9 年前

    以下各项应起作用:

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

    或者,您也可以使用以下逻辑(但我不知道如何将其放入iMacro中):

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