---
title: "Get random integer in range (x, y]?"  
description: "Get random integer in range (x, y]?"  
author: "Manoj Bhatt"  
published: 2013-05-07  
updated: 2013-05-07  
canonical: https://www.mindstick.com/forum/835/get-random-integer-in-range-x-y  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Get random integer in range (x, y]?

Hi Everyone! \
How do I generate a [random](https://www.mindstick.com/forum/33419/generating-random-numbers-in-objective-c) [integer](https://answers.mindstick.com/qa/113667/write-code-for-roman-to-integer) i, such that i belongs to (0,10]?\
I tried to use this:\
Random [generator](https://www.mindstick.com/articles/249204/generator-info-where-can-you-find-the-best-generator-for-power-outages) = new Random();[int](https://www.mindstick.com/forum/159137/how-to-convert-date-int-to-date-in-sql) i = generator.nextInt(10);but it gives me [values](https://www.mindstick.com/forum/327/sum-textbox-values) between [0,10).\
But in my case I need them to be (0,10].\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Manoj!\
Try as following \
Random generator = new Random(); int i = generator.nextInt(10) + 1;


---

Original Source: https://www.mindstick.com/forum/835/get-random-integer-in-range-x-y

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
