Java program to generate unique random number on each call

Home / Uncategorized / Java program to generate unique random number on each call

Java program to generate unique random number on each call

import java.util.HashSet;
import java.util.Random;

public class UniqueRandomNumber 
{
    public static void main(String[] args)
    {
        Random r=new Random();
        HashSet set=new HashSet<>();
        while(set.size()<1)
        {
            int random=r.nextInt(99)+10;
            set.add(random);
        }
        for(int randomNumbers:set)
        {
            System.out.println(randomNumbers);
        }
    }
}

Watch video of this program

Leave a Reply

Your email address will not be published. Required fields are marked *