To show 25 images randomly out of 40 images in a grid view

前端 未结 4 1028
醉梦人生
醉梦人生 2021-01-24 15:45

I am creating an iphone app in which I need to create a grid view of 25 images. I am doing that by taking 25 images in an array, and displaying them by using for loop by changin

4条回答
  •  情书的邮戳
    2021-01-24 16:08

    You essentially want to randomize the order of the images and then pick the first 25. I don't know exactly how you are arranging your data structures, but here is an example with integers:

    for (int x = 39; x > 0; x--)
    {
      int tmp = element[x];
      int newLoc = random()%(x+1);
      element[x] = element[newLoc];
      element[newLoc] = tmp;
    }
    

    I'm assuming that element contains your values that you want to mix up.

提交回复
热议问题