Skip to content

Instantly share code, notes, and snippets.

@vector4wang
Created May 28, 2019 02:48
Show Gist options
  • Save vector4wang/0694b841db6ef3edab2a1abf174d3b78 to your computer and use it in GitHub Desktop.
Save vector4wang/0694b841db6ef3edab2a1abf174d3b78 to your computer and use it in GitHub Desktop.
[概率命中否] 传递一个概率值,计算一次此次是否中奖 #Java #概率命中
/**
* 传入一个概率值,基于此概率计算一次是否有“中奖”
*
* @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;
}
@vector4wang
Copy link
Author

简单粗暴?满足需求?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment