Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Array random problem

807599Dec 21 2006 — edited Dec 22 2006
Hi, I just started working with java and I have probably an easy problem to solve.
I've made an array and I want to fill it with random integers from 0-39. Each integer can be used only once.

Here's the code:
for (i=0; i<40; i++) 
{
  kup[i] = (int)(Math.random() * 40);
  for (j=0; j<40; j++) 
  {
    if (j != i) 
    {
      while (kup[i] == kup[j])
      {
        kup[i] = (int)(Math.random() * 40);
      } 
    }
  }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 19 2007
Added on Dec 21 2006
17 comments
319 views