大神帮我看看,这个抽奖概率的程序写的对吗?
lua吧
全部回复
仅看楼主
level 5
function RandomLottery()
local CurrentAwards;
local A1,A2,A3,A4,A5,A6,A7,A8;
local RandomNumber = math.random(1,10000); --取1到1w随机数
A1 = "10000元" --设置中奖几率为10000分之一
A2 = "8888元" --设置中奖几率为5000分之一
A3 = "5000元" --设置中奖几率为2000分之一
A4 = "2000元" --设置中奖几率为1000分之一
A5 = "888元" --设置中奖几率为500分之一
A6 = "200元" --设置中奖几率为100分之一
A7 = "100元" --设置中奖几率为10分之一
if RandomNumber == 1 then
CurrentAwards = A1;
elseif RandomNumber <= 2 then
CurrentAwards = A2;
elseif RandomNumber <= 5 then
CurrentAwards = A3;
elseif RandomNumber <= 10 then
CurrentAwards = A4;
elseif RandomNumber <= 20 then
CurrentAwards = A5;
elseif RandomNumber <= 100 then
CurrentAwards = A6;
elseif RandomNumber <= 1000 then
CurrentAwards = A7;
else
CurrentAwards = "抱歉,您没有中奖,请再接再厉!";
end;
return CurrentAwards;
end;
2016年03月05日 01点03分 1
level 5
人呢?大神去哪了?
2016年03月07日 13点03分 2
level 5
2016年03月07日 13点03分 3
level 11
没错
2016年03月07日 23点03分 4
level 6
不对
2016年03月08日 08点03分 5
level 6
第二条,elseif把等于1条件是排除的
2016年03月08日 08点03分 6
那应该怎么写?
2016年03月08日 09点03分
把elseif ,独立成if ?
2016年03月08日 09点03分
yes
2016年03月08日 09点03分
@爱喝茶的乾坤圈 那不行啊,那样会同时满足条件,CurrentAwards 会等于最后一个满足条件的
2016年03月08日 09点03分
1