Use a recursive loop and an int to keep track of your progress towards your desired count of 50.
Each time through the loop, you'll want to:
- Generate a new random number (0-4)
- Use your random number to select an image from your array
- Add your random number to your int and check to see if you've hit 50.
- If you've hit 50, you're done
- If you haven't hit 50, do it again.
Something like this:
//in your .h declare an int to track your progress
int myImgCount;
//in your .m
-(void)randomizeImages {
//get random number
int randomImgNum = arc4random_uniform(5);
//use your random number to get an image from your array
UIImage *tempImg = [_imageArray objeactAtIndex:randomImgNum];
//add your UIImage to a UIImageView and place it on screen somewhere
UIImageView *tempImgView = [[UIImageView alloc] initWithImage:tempImg];
//define the center points you want to use
tempImgView.center = CGPointMake(yourDesiredX,yourDesiredY);
[self addSubview:tempImgView];
[tempImgView release];
//increment your count
myImgCount = myImgCount+(randomImgNum+1);
//check your count
if (myImgCount<50) {
[self randomizeImages]; //do it again if not yet at 50
}
}
Something like that should work for you.