Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在 1-6 范围内创建 2 个随机整数数组。但我一直得到相同的数字。
Random random = new Random(); for (int i = 0; i < 5; i++) { player1[i] = random.nextInt(6) + 1; player2[i] = random.nextInt(6) + 1; }
您的代码应该返回预期的结果。
我宁愿用这个。
Min + (int)(Math.random() * ((Max - Min) + 1))
从上面生成的随机数将包含 Min 和 Max Exclusive