Usage of random.nextInt()
1. nextInt() without parameters will generate all valid integers (including positive numbers) , negative number, 0)
2. NextInt(int x) with parameters will generate an arbitrary positive integer in the range of 0~x (excluding X)
For example: int x =new Random.nextInt(100);
Then x is an arbitrary integer from 0 to 99
3. Generate an integer within the specified range
/* * 生成[min, max]之间的随机整数 * @param min 最小整数 * @param max 最大整数 */ private static int randomInt(int min, int max){ return new Random().nextInt(max)%(max-min+1) + min; }
For example: call The method randomInt(10,20); will generate an arbitrary integer within the [10,20] set
Recommended tutorial: "java tutorial"
The above is the detailed content of random.nextint() detailed explanation. For more information, please follow other related articles on the PHP Chinese website!