---
title: "Generate random numbers between two numbers"  
description: "Generate random numbers between two numbers"  
author: "Anonymous User"  
published: 2013-05-07  
updated: 2013-05-07  
canonical: https://www.mindstick.com/forum/834/generate-random-numbers-between-two-numbers  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Generate random numbers between two numbers

Hi Guys!\
[public](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) TestSample { public [static void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) main([String](https://www.mindstick.com/articles/1527/string-split-in-c-sharp)[] args) { \
int a = Integer.parseInt(args[0]); int b = Integer.parseInt(args[1]);\
double ran = Math.random(); }}I don't want to use Random r = new Random(); class. Is there any other way to [generate random](https://www.mindstick.com/forum/159580/how-to-generate-random-numbers-in-c-sharp) numbers. I am just struck with what [logic](https://www.mindstick.com/articles/331924/best-ways-to-improve-your-logic-building-skills-for-programming) could be applied to generate [random numbers](https://www.mindstick.com/forum/832/generate-random-numbers-uniformly-over-entire-range) between two numbers.\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Jeet!\
Consider using this code:\
int a = Integer.parseInt(args[0]);int b = Integer.parseInt(args[1]);double ran = Math.[random](https://www.mindstick.com/forum/33419/generating-random-numbers-in-objective-c)();double random;\
if(a < b) random = (b-a)*ran + a;else random = (a-b)*ran + b;This will work for a >= 0 and b >= 0 if yo consider using negative number the logic sligtly changes


---

Original Source: https://www.mindstick.com/forum/834/generate-random-numbers-between-two-numbers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
