如下列代码,50%的概率返回A,20%的概率返回B,30%的概率返回C

var d = Math.random();
if (d < 0.5)
    // 50% chance of being here
    return 'A';
else if (d < 0.7)
    // 20% chance of being here
    return 'B';
else
    // 30% chance of being here
    return 'C';

标签: random函数 概率 返回值


阿里云优惠主机

添加新评论

免责声明
本博客部分内容来自于互联网,不代表作者的观点和立场,如若侵犯到您的权益,请联系[email protected]。我们会在24小时内进行删除。