Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

shaaoteiman
Copy link

修改随机红包产生规则

修改随机红包产生规则
@crossoverJie
Copy link
Owner

@shaaoteiman

请描述下调整的原因。

@shaaoteiman
Copy link
Author

通过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;

//变量定义
Copy link
Owner

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 ;
//金额检查,如果最大红包 * 个数 < 总金额或最小红包 * 个数 > 总金额;则需要调整红包总金额
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里没必要抛异常了,像以前直接打印也没问题。不然所有的单测都需要改。

Repository owner deleted a comment from yjw0513 Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants