0

I have tried the following code. It loads images quite randomly but some images appear to be the same. Can my code be modified to have all the images uniquely and randomly loaded?

 int[] imageViews = {
            R.id.ImageView2, R.id.ImageView2,
            R.id.ImageView3, R.id.ImageView4,
            R.id.ImageView5, R.id.ImageView6,
            R.id.ImageView7, R.id.ImageView8,
            R.id.ImageView9
            };

        int[] images = {
            R.drawable.m1, R.drawable.m2,
            R.drawable.m3, R.drawable.m4,
            R.drawable.m5, R.drawable.m6,
            R.drawable.m7, R.drawable.m8,
            R.drawable.m9

            };

        Random random = new Random(System.currentTimeMillis());

        for(int v : imageViews) {
            ImageView iv = (ImageView)findViewById(v);
            iv.setImageResource(images[random.nextInt(images.length - 1)]);
slayton
  • 20,123
  • 10
  • 60
  • 89
rijinrv
  • 2,029
  • 2
  • 16
  • 17

2 Answers2

0

Edit: Remove the images from the array as you're displaying them. Recalculate your random bounds to use a shorter array bound.

jlindenbaum
  • 1,891
  • 18
  • 28
  • danx..i thought d same as u.. but still am in search some other functions that can easily solve ma prob. – rijinrv Jan 23 '12 at 03:19
0

check about this solution , this was worked for me..Random images without repetition

Community
  • 1
  • 1
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166