public Integer getRand() {
Integer result = null;
int sum = 100;//后台可更改
int randomNum = new Random().nextInt(sum);// 随机生成1到sum的整数
if (randomNum == 1) {
result = 1;// 一等奖
} else if (randomNum < 5) {
result = 2; // 二等奖
} else if (randomNum <10) {
result = 3; // 三等奖
}
return result;
}
这个概率应该后台可以控制吧!
后台管理有个字段,用来写各个奖品获得概率,
只要我是问问 这样靠谱吗?
大家有啥好的建议!!
其实,概率后台来设定是不是不公平???
不透明!
嗯。。
有多少人抽奖 也不是预知的,
我再思考思考
sum 调成1000,
一等奖 中奖率是千分之一吗???
public Integer getRand() {
Integer result = -1;
int sum = 1000;// 后台可修改
int randomNum = new Random().nextInt(sum);// 随机生成1到sum的整数
int time = new Date().getSeconds() % 2;// 秒数为2 的倍数
if (time == 0) {
if (randomNum == 1) {
result = 1;// 一等奖
} else if (randomNum < 5) {
result = 2; // 二等奖
} else if (randomNum < 25) {
result = 3; // 三等奖
}
}
return result;
}