Creating unique random numbers ​
<p>i was making a Random number (sort of a guessing game) and have come up with the ff. code to generate 10 one or two-digit numbers(1 or 10 up to 40):</p>

<pre><code>public void generate()
{
        for(int i=0; i&lt;=1; i++)
        {
            for(int l=0; l&lt;10; l++)
            {
                Random rdm=new Random();
                arr[l] = rdm.nextInt(range)+1;

            }
        }
}
</code></pre>

<p>However, this code only answers the need to generate 10 random one or two-digit numbers. I need to make this program generate unique random numbers. How can I do that?</p>

<p>sorry for the late update... what i want to do with this program is that if the array contains a duplicate, that duplicate would be replaced with a unique one...</p>

<p>==============SOLVED================</p>

<p>NEW PROBLEM:</p>

<pre><code>HashSet set=new HashSet();
    Random random=new Random();

    while(set.Size()&lt;10)
    {
        set.add(random.nextInt(range)+1);
    }

    lbtest.setText(set.toString());
    bgen.setEnabled(false);
    gametext.setText("");
</code></pre>

<p>As requested by ggrigery:</p>

<p>here's the updated code in reference to ggrigery's suggestion.</p>
