0

Ok, so I'm working on this application and I am having one problem... So far the set up is this. I have 16 buttons that are set up as images. I have arc4random() %16 set on all of them so that all the buttons have an equal chance of being one of the 16 images. I set up a switch statement for each of the picture types and have each case equal a different image. Now, what I want is for all the images to be used once... No repeats when the application runs, I just want them in random order. Is there any way I can do that? Currently when I run the app, some images appear more than once because each button can be one of the 16 images. I just want the image to appear once. I'm not sure what to do, maybe add 16 if/if else statements inside each case??? please help!!! Here is my current syntax for the first switch statement. Thanks!

-(void)Picture1SelectedType{

switch (Picture1Type) {
    case 0:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Plastic-Brick-Man@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];

    }
        break;
    case 1:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Games-Console---1@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 2:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Old-Telephone@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 3:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Scarf@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 4:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Camera@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 5:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Tea-Cup@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 6:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Fruit-Computer---3@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 7:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Sugary-Drink@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 8:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Fruit-Computer@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 9:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Pocket-Watch@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 10:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Starship@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 11:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Games-Controller---1@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 12:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Two-tone-Shoe@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 13:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Lightbulb@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 14:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Bike@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;
    case 15:
    {
        UIImage *pictureImage = [UIImage imageNamed: @"Flower-Vase@Low.png"];
        [Picture1 setImage:pictureImage forState:UIControlStateNormal];
        [self.view addSubview:Picture1];
    }
        break;

    default:

        break;
}
i_am_jorf
  • 53,608
  • 15
  • 131
  • 222

1 Answers1

0

Add the images to an array, then use the code here to randomly shuffle the array.

Community
  • 1
  • 1
i_am_jorf
  • 53,608
  • 15
  • 131
  • 222