10-01
29

js概率出现次数计算代码

<script>
var a='我是大哥';
var b='我是二哥';
var c='我是三弟';
var x=Math.floor(Math.random()*10+1);//1-10之间随机数
switch(x)
{
case 1:
case 2:alert(a);break; //1和2时,弹出a,正好百分之20
case 3:
case 4:
case 5:alert(b);break;  //3、4、5时弹出b,百分之30
case 6:
case 7:
case 8:
case 9:
case 10:alert(c);break; //剩下的百分之50
}
</script>


文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.