Possible Duplicate:
Generate unique random numbers in Java
I am creating a lottery app for android which will generate a set of 6 numbers between 1 and 49. The problem I am having is how can I make these numbers unique.
Random r = new Random();
int n1=r.nextInt(48) + 1;
ball1.setText(String.valueOf(n1));
int n2=r.nextInt(48) + 1;
ball2.setText(String.valueOf(n2));
int n3=r.nextInt(48) + 1;
ball3.setText(String.valueOf(n3));
int n4=r.nextInt(48) + 1;
ball4.setText(String.valueOf(n4));
int n5=r.nextInt(48) + 1;
ball5.setText(String.valueOf(n5));
int n6=r.nextInt(48) + 1;
ball6.setText(String.valueOf(n6));