📜  如何在java代码示例中添加负随机数

📅  最后修改于: 2022-03-11 14:52:24.234000             🧑  作者: Mango

代码示例1
//To get a random number between a set range with min and max:

int number = random.nextInt(max - min) + min;
//It also works with negative numbers.

//So:

random.nextInt(30 + 10) - 10;
// max = 30; min = -10;
//Will yield a random int between -10 and 30 (exclusive).

//It also works with doubles.