Generate Random Numbers Between Two Numbers in Java

Java Program to generate Random numbers between the given interval numbers


Here this java program will generate random number between the specified interval. You can change the lower limit to generate random number by changing value for lLimit and similarly for uLimit. generateRandomNumber method will to the random number generation task. We used java.util.Random class to generate the random number.

import java.util.Random;
class RandNum{
public static void main(String arg[]){
int lLimit=10,uLimit=50;
int randNumber=generateRandomNumber(lLimit,uLimit);
System.out.println("Generated Random Number: "+ randNumber);
}

public static int generateRandomNumber(int st,int end){
Random r = new Random();
return (r.nextInt(end-st)+st);
}


Related Topic Create Random String,Password
Java - Create Random Number
Prime Number Program in Java
How to Create Random Number Program in C Code
Print Fibonacci Numbers in Java
Java  random  

nScraps.com 2011   Privacy Policy  Terms of Service  Feedback