This is how i am generating a unique no in between 1 to 6 and getting appropriate images from the drawable folder.
Random rand = new Random();
// n = the n
Here's the easiest code to do it and store into an array without any repetition:
Random rand = new Random();
int[] ar;
ar = new int[5];
int random = 0;
int [] result_arr=new int[5];
boolean flag=false;
for(int i=0;i<5;i++)
{
ar[i]=0;
do{
random =rand.nextInt(10);
flag=false;
for(int j=0;j<i;j++)
{
if(ar[j]==random)
flag=true;
}
if(!flag)
{
ar[i]=random;
break;
}
}
while(true) ;
}
this will create unique numbers in the array