所以我有这样的一段代码选择随机
if (x >= gameView.getWidth()) { //if gone of the right side of screen
x = x - gameView.getWidth(); //Reset x
y = random.nextInt(gameView.getHeight());
xSpeed =
ySpeed =
}
,但我需要得到双方xSpeed
和ySpeed
两个值之间进行选择,无论是“10”或“-10”,只有那些两个数字之间没有任何内容。
无论我已经看了说使用random.nextInt
但也从这些数字中选择-10到10之间......
random.nextInt(n)给出0和n之间的随机数。它绝不会在负数和正数之间平均分配。 –
你是对的。我的错。编辑答案。 – Tarmo