```
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

Carvia Tech | December 27, 2017 | 1 min read | 52 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, how would you sort them in Big O(n) time
- Diamond Problem of Inheritance in Java 8
- can we write a java method that swaps two integers
- How to configure custom ThreadPool for Java 8 Stream API parallel operations
- What is ThreadLocal in Java, where will you use this class
- How will you calculate factorial of a large number in Java
- Find missing numbers in 4 billion unique numbers with 50MB RAM

###### Find more on this topic:

##### Core Java

Core Java - OOP Concepts, Garbage Collection, Multi-threading, Collections Framework, Java 8 Features, Lambda Functions, Streams.

Last updated 1 week ago

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

You may also be interested in..

You may also be interested in..

You may also be interested in..

You may also be interested in..

##### Similar Posts

- Explain Java Exception Class Hierarchy
- Http download using Java NIO FileChannel
- CRC32 checksum calculation Java NIO
- Set precision and scale for a double value in java
- Difference between HashMap, LinkedHashMap and TreeMap
- What is difference between ExecutorService submit and execute method
- What is left shift right shift and unsigned rght shift operator in Java
- What happens when wait() & notify() method are called
- can we write a java method that swaps two integers
- Find missing numbers in 4 billion unique numbers with 50MB RAM

Free Email Updates

Enter your email address to subscribe to this blog and receive notifications of new posts by email.