Created
May 28, 2019 02:48
-
-
Save vector4wang/0694b841db6ef3edab2a1abf174d3b78 to your computer and use it in GitHub Desktop.
[概率命中否] 传递一个概率值,计算一次此次是否中奖 #Java #概率命中
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 传入一个概率值,基于此概率计算一次是否有“中奖” | |
* | |
* @param proVal 概率值,如概率为0.01,则proVal为1,概率为0.2,则proVal为20 | |
* @return | |
*/ | |
public static boolean isLuckyVal(int proVal) { | |
int val = new Random().nextInt(100)+1; | |
if (proVal <= val) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
简单粗暴?满足需求?