gpt4 book ai didi

java - 许可证 key 生成器冲突概率

转载 作者:行者123 更新时间:2023-12-01 18:13:46 24 4
gpt4 key购买 nike

我编写了生成许可证 key 的代码。

*必须是 A-Z 或 0-9(36 种可能性)

*前4位始终为MKDC,接下来的16位随机生成

我想了解如何计算冲突概率(2 个生成的许可证相同)。

public class Random {

public static void main(String[] args) {
String licensestring = "MKDC-";
char license[] = {
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'
};

int x = 0;
while (x < 16){
java.security.SecureRandom rand = new java.security.SecureRandom();
int randomNumber = rand.nextInt(36);
licensestring = licensestring + license[randomNumber];
x = x + 1;
if (x == 4 || x == 8 || x == 12){
licensestring = licensestring + "-";
}
}
System.out.println(licensestring);
}

}

最佳答案

对于两个生成的许可证,其中一个的可变字符必须与另一个的可变字符匹配。这等于概率

1/36^16

该值大约为 0.00000000000000000000000125。

但是,对于多个许可证,概率会增加。对于 n 个许可证,概率为:

36^16 PERMUTE n, all over 36^(16n)

key 空间非常巨大,Wolfram|alpha 为 unable to determine使用当前方法对合理数量的键进行碰撞的概率。

关于java - 许可证 key 生成器冲突概率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31010020/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com