!146 无符号算数验证码两个随机数生成相同概率较高问题

Merge pull request !146 from tmjAccount/dev
This commit is contained in:
疯狂的狮子Li 2022-02-24 05:09:37 +00:00 committed by Gitee
commit 77756eb08d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -41,14 +41,14 @@ public class UnsignedMathGenerator implements CodeGenerator {
@Override
public String generate() {
final int limit = getLimit();
int min = RandomUtil.randomInt(limit);
int max = RandomUtil.randomInt(min, limit);
String number1 = Integer.toString(max);
String number2 = Integer.toString(min);
number1 = StringUtils.rightPad(number1, this.numberLength, CharUtil.SPACE);
number2 = StringUtils.rightPad(number2, this.numberLength, CharUtil.SPACE);
int a = RandomUtil.randomInt(limit);
int b = RandomUtil.randomInt(limit);
String max = Integer.toString(Math.max(a,b));
String min = Integer.toString(Math.min(a,b));
max = StringUtils.rightPad(max, this.numberLength, CharUtil.SPACE);
min = StringUtils.rightPad(min, this.numberLength, CharUtil.SPACE);
return number1 + RandomUtil.randomChar(OPERATORS) + number2 + '=';
return max + RandomUtil.randomChar(OPERATORS) + min + '=';
}
@Override