当前位置:网站首页>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
- Library cache lock brought by add trandata
- 牛客網:三數之和
- Generate API documents using swagger (go language example)
- Is foreign exchange speculation formal and is the fund safe?
- Solve the cvxpy error the solver GLPK_ MI is not installed
- [tutorial] Firefox send: deployment method of Firefox open source temporary file sharing service platform
- [leetcode 16 solution] the sum of the nearest three numbers
- 同花顺能开户吗,在APP上可以直接开通券商安全吗 ,买股票怎么网上开户
- Social metauniverse: start from redefining yourself
猜你喜欢

Properties to YML

It has been engaged in the functional test of 10K to the test development of 40W annual salary for 5 years, and spent 7 days sorting out the super comprehensive learning route
![[leetcode 7 solution] integer inversion](/img/72/b358a67eaedda48e1c0aebdaec04a5.jpg)
[leetcode 7 solution] integer inversion

How to determine fragment restored from Backstack

Zhangqiming, vice director of the United Front Work Department of the CPC Anhui Provincial Committee, led a team to investigate the HoloNet Royal Hefei R & D base

Successful transition from self-study test halfway, 10K for the first test
![[live streaming] understand the design of d3js and learn how to read the source code.](/img/31/53e2d267acda0f87bcef081f2ebc8b.jpg)
[live streaming] understand the design of d3js and learn how to read the source code.

(11) Image frequency domain filtering with OpenCV

同时做测试,别人已经年薪20w起,为什么你还在为达到月薪10k而努力?

The required books for software testers (with e-books) recommended by senior Ali have benefited me a lot
随机推荐
remote: Support for password authentication was removed on August 13, 2021
Deploy etcd cluster in static pod mode
P5076 【深基16.例7】普通二叉树(简化版)
How to determine the sample size of an inspection lot in SAP QM's initial sampling strategy?
China hydraulic press market trend report, technical innovation and market forecast
Junda technology is applicable to "kestar" intelligent precision air conditioning network monitoring
Before job hopping, Jin San made up the interview questions. Jin San successfully landed at Tencent and got a 30K test offer
初步了解认识正则表达式(Regex)
Foreign brands become a thing of the past? What are the key words of the TV industry in 2022?
MinIO客户端(mc命令)实现数据迁移
Lua pattern matching
[untitled]
Niuke net: somme des trois nombres
How do testers plan for their future? To achieve 25K in 2 years?
Listener in JSP
Niuke.com: sum of three numbers
EU officially released the data act, Ukraine was attacked by DDoS again, kitchen appliance giant Meiya was attacked, internal data leakage network security weekly
How to download putty using alicloud image?
初步了解認識正則錶達式(Regex)
New product release Junda intelligent integrated environmental monitoring terminal