安卓相同seed随机数不同,java端口正常


public static String getRandom(int length,long seed) {
        StringBuilder ret = new StringBuilder();
        random.setSeed(seed);
        for (int i = 0; i < length; i++) {
            boolean isChar = (random.nextInt(2) % 2 == 0);// 输出字母还是数字
            if (isChar) { // 字符串
                int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; // 取得大写字母还是小写字母
                ret.append((char) (choice + random.nextInt(26)));
            } else { // 数字
                ret.append(Integer.toString(random.nextInt(10)));
            }
        }
        return ret.toString();
   }

img

img

img

java中Random是伪随机,有时候随机数会相同,如果想让生成的随机数更加无法预测,可以用Random.setseed()设置随机数种子,使随机数更加随机。

你想说相同的代码,androidstudio和idea运行出来结果不一样?