gpt4 book ai didi

java - Android API 级别 19 及以下的 ThreadLocalRandom() 替代方案?

转载 作者:行者123 更新时间:2023-12-02 11:42:22 27 4
gpt4 key购买 nike

在我的应用程序中,我使用 ThreadLocalRandom() 生成种子,但它仅适用于 API 级别 21 +,我可以使用 Random code> 并得到相同的结果?

这是代码:

public String generateSeed(int length, boolean isNumeric) {
String key = "";
if (isNumeric) {
while (key.length() < length) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
key = key + ThreadLocalRandom.current().nextInt(0, 9);
} else {
//TODO: ThreadLocalRandom alternative
}

}
} else {
while (key.length() < length) {
key = key + UUID.randomUUID().toString().replace("-", "");
}
}
key = key.substring(0, length);
return key;
}

最佳答案

只需使用随机。它的作用是一样的。您可能需要考虑使用 currentTimeMillis 作为种子,但如果您不需要自定义种子,则不必提供任何参数来创建它

关于java - Android API 级别 19 及以下的 ThreadLocalRandom() 替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48461128/

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