如何改写Java转盘抽奖算法为长尾?
- 内容介绍
- 文章标签
- 相关推荐
本文共计428个文字,预计阅读时间需要2分钟。
javapublic class LuckDraw { public int getPrizeIndex(List prizes) throws Exception { int random=-1; // 计算总权重 double sumWeight=0; for (GoodsEntity p : prizes) { sumWeight +=p.getPrizeWeight(); } // 生成随机数 random=(int) (Math.random() * sumWeight); return random; }}
public class LuckDraw {
public int getPrizeIndex(List
@Entity @Table(name = "goods") public class GoodsEntity { private Long goodsId; private String goodsName; private Byte dataStatus; private Timestamp createTime; private Byte ranking; private Integer prizeWeight; private BigDecimal price; private Integer version; @Id @Column(name = "goods_id", nullable = false) public Long getGoodsId() { return goodsId; } public void setGoodsId(Long goodsId) { this.goodsId = goodsId; } @Basic @Column(name = "goods_name", nullable = true, length = 50) public String getGoodsName() { return goodsName; } public void setGoodsName(String goodsName) { this.goodsName = goodsName; } @Basic @Column(name = "data_status", nullable = true) public Byte getDataStatus() { return dataStatus; } public void setDataStatus(Byte dataStatus) { this.dataStatus = dataStatus; } @Basic @Column(name = "create_time", nullable = false) public Timestamp getCreateTime() { return createTime; } public void setCreateTime(Timestamp createTime) { this.createTime = createTime; } @Basic @Column(name = "ranking", nullable = true) public Byte getRanking() { return ranking; } public void setRanking(Byte ranking) { this.ranking = ranking; } @Basic @Column(name = "prize_weight", nullable = true) public Integer getPrizeWeight() { return prizeWeight; } public void setPrizeWeight(Integer prizeWeight) { this.prizeWeight = prizeWeight; } @Basic @Column(name = "version", nullable = true) public Integer getVersion() { return version; } public void setVersion(Integer version) { this.version = version; } @Basic @Column(name = "price", nullable = true) public BigDecimal getPrice() { return price; } public void setPrice(BigDecimal price) { this.price = price; } } Controller代码
public Map
本文共计428个文字,预计阅读时间需要2分钟。
javapublic class LuckDraw { public int getPrizeIndex(List prizes) throws Exception { int random=-1; // 计算总权重 double sumWeight=0; for (GoodsEntity p : prizes) { sumWeight +=p.getPrizeWeight(); } // 生成随机数 random=(int) (Math.random() * sumWeight); return random; }}
public class LuckDraw {
public int getPrizeIndex(List
@Entity @Table(name = "goods") public class GoodsEntity { private Long goodsId; private String goodsName; private Byte dataStatus; private Timestamp createTime; private Byte ranking; private Integer prizeWeight; private BigDecimal price; private Integer version; @Id @Column(name = "goods_id", nullable = false) public Long getGoodsId() { return goodsId; } public void setGoodsId(Long goodsId) { this.goodsId = goodsId; } @Basic @Column(name = "goods_name", nullable = true, length = 50) public String getGoodsName() { return goodsName; } public void setGoodsName(String goodsName) { this.goodsName = goodsName; } @Basic @Column(name = "data_status", nullable = true) public Byte getDataStatus() { return dataStatus; } public void setDataStatus(Byte dataStatus) { this.dataStatus = dataStatus; } @Basic @Column(name = "create_time", nullable = false) public Timestamp getCreateTime() { return createTime; } public void setCreateTime(Timestamp createTime) { this.createTime = createTime; } @Basic @Column(name = "ranking", nullable = true) public Byte getRanking() { return ranking; } public void setRanking(Byte ranking) { this.ranking = ranking; } @Basic @Column(name = "prize_weight", nullable = true) public Integer getPrizeWeight() { return prizeWeight; } public void setPrizeWeight(Integer prizeWeight) { this.prizeWeight = prizeWeight; } @Basic @Column(name = "version", nullable = true) public Integer getVersion() { return version; } public void setVersion(Integer version) { this.version = version; } @Basic @Column(name = "price", nullable = true) public BigDecimal getPrice() { return price; } public void setPrice(BigDecimal price) { this.price = price; } } Controller代码
public Map

