```
private static int getRandomNumberInRange(int min, int max) {
Random r = new Random();
return r.ints(min, (max + 1)).findFirst().getAsInt();
}
```

# Generate Random Numbers in a range using Java 8

Upasana | December 27, 2017 | 1 min read | 208 views | Java 8

## Java 8 Random.ints

In Java 8, new methods are added in java.util.Random

This Random.ints(int origin, int bound) or Random.ints(int min, int max) generates a random integer from origin (inclusive) to bound (exclusive).

3.1 Code snippet.

##### Top articles in this category:

- Given a collection of 1 million integers, all ranging between 1 to 9, sort them in Big O(n) time
- Secure OTP generation in Java
- Factorial of a large number in Java BigInteger
- Java 8 Parallel Stream custom ThreadPool
- Diamond Problem of Inheritance in Java 8
- can we write a java method that swaps two integers
- Find missing numbers in 4 billion unique numbers with 50MB RAM

###### Recommended books for interview preparation:

Book you may be interested in..

Book you may be interested in..