[英]Create 2 arrays of random integers
I'm trying to create 2 arrays of random integers in the range 1-6. 我正在尝试创建1-6范围内的2个随机整数数组。 But I keep getting the same numbers. 但是我一直得到相同的数字。
Random random = new Random();
for (int i = 0; i < 5; i++) {
player1[i] = random.nextInt(6) + 1;
player2[i] = random.nextInt(6) + 1;
}
your code should return what's expected. 您的代码应返回预期的结果。
I would use this rather. 我宁愿用这个。
Min + (int)(Math.random() * ((Max - Min) + 1))
random number generated from above will be Min inclusive and Max Exclusive 从上面生成的随机数将是“最小”和“最大”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.