I have the array of images with a length of 6 (we call array first).I want to save this 6 values in another array with a length of 12 so that each value of the first array repeated twice in the second array and the values placed in random places of the second array .
For example : first array = {3,4,20,33,1,25}
The second array can be = {4,20,33,1,20,25,25,3,4,1,3,33}
public class PlayActivity extends AppCompatActivity {
public static boolean isTheSameOk = true;
final Random rnd = new Random();
int saverandom;
int dontsame = 0 ;
int [] allimages = {R.drawable.img1, R.drawable.img2, R.drawable.img3, R.drawable.img4, R.drawable.img5,
R.drawable.img6, R.drawable.img7, R.drawable.img8, R.drawable.img9, R.drawable.img10, R.drawable.img11,
R.drawable.img12, R.drawable.img13, R.drawable.img14, R.drawable.img15, R.drawable.img16, R.drawable.img17,
R.drawable.img18, R.drawable.img19, R.drawable.img20, R.drawable.img21, R.drawable.img22, R.drawable.img23,
R.drawable.img24, R.drawable.img25, R.drawable.img26, R.drawable.img27, R.drawable.img28, R.drawable.img29,
R.drawable.img30, R.drawable.img31, R.drawable.img32, R.drawable.img33, R.drawable.img34, R.drawable.img35,
R.drawable.img36, R.drawable.img37, R.drawable.img38, R.drawable.img39, R.drawable.img40};
int [] chooseimages = new int [6];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
//choose 6 image from 40 image we have for putting into buttons
for(int counter = 0 ; counter<6 ; counter++){
saverandom = rnd.nextInt(39);
if(DontSameChoose(allimages[saverandom])){
chooseimages[counter] = saverandom;
}else {
counter--;
}
}
//put the select images in buttons
}
protected boolean DontSameChoose (int imageid){
for(int c = 0 ; c<6 ; c++){
if(imageid == chooseimages[c]){
isTheSameOk = false;
}
}
return isTheSameOk;
}
}
the first array is choose images that have the 6 id of the images and i want to save the values in the way i said above in the another array with the lenght of 12 .