Avatar ·

How to generate a random integer in a given range in Java?

Hello everyone! I just started learning Java and came across a task that seems simple but is causing me difficulties. I need to generate a random integer in a specific range, for example, from 1 to 10 (inclusive). I know that Java has a `Random` class, and I tried using the `nextInt()` method, but it returns numbers from 0 to some limit. Here's what I wrote: ```java import java.util.Random; public class TestRandom { public static void main(String[] args) { Random rand = new Random(); int randomNumber = rand.nextInt(10); // I get numbers from 0 to 9 System.out.println(randomNumber); } } ``` The problem is that I need the range to start not from 0, but from an arbitrary number, for example, from 5 to 15. I tried adding