i have used this formula to generate random number.

Integer random_number = new Integer((int)(Math.floor(Math.random() * (max - min + 1)) + min));
while(numbers.size() < noofQn ) 
{
Integer random_number = new Integer((int)(Math.floor(Math.random() * (max - min + 1)) + min));
System.out.println("Random number"+ random_number );
if(!numbers.contains(random_number))
{
numbers.add(random_number);
}
}

numbers is an arraylist.
noofQn to be displayed.
when i enter noofqn=4 when total 5 records are there it goes to infinite loop.for eg max=1 min=5 noofQn=4 it goes to an infinite loop
can anyone tell how to generate random number to add in arraylist so that it wont repeat again

Why is it that you want to write your own when Java has a rather good random number generator built in?