当前位置:网站首页>Draw according to weight
Draw according to weight
2022-06-12 20:54:00 【Dong_ cson】
/**
*
* @param request Blind box lucky draw
* @param request
* @return
*/
@Override
public BGitf lotteryResults(HttpServletRequest request) {
BUserInfo userInfo = ibUserInfoService.validationToken(request);
Long id = userInfo.getId();
String phoneNum = userInfo.getPhoneNum();
String nickName = userInfo.getNickName();
String isNewUser = userInfo.getIsNewUser();
Assert.isTrue(isNewUser.equals("1"), " I'm sorry , You are not a new user ");
List<BGitf> bGitfs = bGitfMapper.selectBGitfList( new BGitf());
BGitf bGitf = mainWeightRandom(bGitfs);
Long gitfId = bGitf.getGitfId();
String gitfName = bGitf.getGitfName();
String gitfImge = bGitf.getGitfImge();
BUserAwardRecord bUserAwardRecord = new BUserAwardRecord();
bUserAwardRecord.setUserId(id);
bUserAwardRecord.setAwardId(gitfId);
bUserAwardRecord.setAwardName(gitfName);
bUserAwardRecord.setGitImge(gitfImge);
bUserAwardRecord.setUserName(nickName);
bUserAwardRecord.setUserPhone(phoneNum);
bUserAwardRecord.setCreateTime(new Date());
bUserAwardRecordMapper.insertBUserAwardRecord(bUserAwardRecord);
isNewUser = "1";
userInfo.setIsNewUser(isNewUser);
bUserInfoMapper.updateBUserInfo(userInfo);
String token = UUID.randomUUID().toString();
redisTemplate.opsForValue().set(token, JSON.toJSONString(userInfo),5, TimeUnit.HOURS);
return bGitf;
}
/**
* Lottery method
* @param awardEntities
* @return
*/
// Weight master method
public static BGitf mainWeightRandom(List<BGitf> awardEntities) {
Integer weightSum = 0;
// Calculate the total weight
for (BGitf wc : awardEntities) {
weightSum += wc.getGitfProbability();
}
if (weightSum <= 0) {
return null;
}
// n in [0, weightSum)
// Produce a [0, weightSum) The random number
Random random = new Random();
Integer n = random.nextInt(weightSum);
// The judgment is in that weight range
Integer m = 0;
for (BGitf wc : awardEntities) {
if (m <= n && n < m + wc.getGitfProbability()) {
return wc;
}
m += wc.getGitfProbability();
}
return null;
}边栏推荐
- remote: Support for password authentication was removed on August 13, 2021
- Detect current system language
- How do testers plan for their future? To achieve 25K in 2 years?
- 可测性设计学习笔记
- 20 shortcut keys for vs code!
- test
- 测试人如何规划自己的未来?才能实现入行2年达到25k?
- Successful transition from self-study test halfway, 10K for the first test
- Summary of machine learning materials
- Go memory escape analysis
猜你喜欢

Data visualization - histogram

EditText控制从左上角开始

Solve the cvxpy error the solver GLPK_ MI is not installed

Lake shore PT-100 platinum resistance temperature sensor

Niuke.com: sum of three numbers

Properties to YML

House raiding 3

Scope and scope chain

Data visualization - Calendar chart

The required books for software testers (with e-books) recommended by senior Ali have benefited me a lot
随机推荐
多机房动环状态网络触摸屏监控解决方案
Analysis of test questions in Chapter 13 of PMP preparation
Double carbon in every direction: green demand and competition focus in the calculation from the east to the West
做自媒体视频,友好的新媒体运营必备app分享
Research Report on hydraulic injection machine industry - market status analysis and development prospect forecast
Can flush open an account? Can you directly open the security of securities companies on the app? How to open an account online when buying stocks
Junda technology is applicable to "kestar" intelligent precision air conditioning network monitoring
逐向双碳:东数西算中的绿色需求与竞争焦点
Social metauniverse: start from redefining yourself
Can tonghuashun open an account? Can tonghuashun directly open the security of securities companies on the app? How to open an account online when buying stocks
What's a good gift for the goddess Festival? Gift recommendation for the goddess Festival on March 8
What are the disadvantages of bone conduction earphones? Analysis of advantages and disadvantages of bone conduction earphones
View 的事件分发机制
Lx09 query tr list of SAP WM preliminary level
How to improve communication efficiency during home office | community essay solicitation
DFT learning notes
How to determine the sample size of an inspection lot in SAP QM's initial sampling strategy?
Do we media video, and share the necessary app for friendly new media operation
Preliminary understanding of regular expressions (regex)
How to determine fragment restored from Backstack