-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update RedPacket.java #119
base: master
Are you sure you want to change the base?
Conversation
修改随机红包产生规则
请描述下调整的原因。 |
通过debug发现,发现(int) (Math.random() * (maxMoney - minMoney) + minMoney)这段代码,在minMoney为19999的时候,由于maxMoney等于200*100,那么这段代码的结果恒为19999,所以带入参数(40000,2)的情况下导致剩余的那个红包一直等于20001 |
补齐变量定义
@@ -40,16 +40,16 @@ | |||
* 最大的红包是平均值的 TIMES 倍,防止某一次分配红包较大 | |||
*/ | |||
private static final double TIMES = 2.1F; | |||
|
|||
//变量定义 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请将注释换为 Javadoc
的形式。
if (MAX_MONEY * count <= money) { | ||
System.err.println("请调大最小红包金额 MAX_MONEY=[" + MAX_MONEY + "]"); | ||
return moneys ; | ||
//金额检查,如果最大红包 * 个数 < 总金额或最小红包 * 个数 > 总金额;则需要调整红包总金额 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里没必要抛异常了,像以前直接打印也没问题。不然所有的单测都需要改。
修改随机红包产生规则