take out objects from randomizer obj c
Posted
by David Pollak
on Stack Overflow
See other posts from Stack Overflow
or by David Pollak
Published on 2010-03-26T18:55:49Z
Indexed on
2010/03/26
19:03 UTC
Read the original article
Hit count: 422
hello everyone, I'm a new "developer" trying to build some iPhone app I'm making an app which gets text from a list of objects in a NSArray and then randomizes them and display one in a TextView, here's the code:
- (IBAction)azione{
NSArray *myArray= [NSArray arrayWithObjects: @"Pasta",@"Pizza",@"Wait",@"Go", nil];
int length = [myArray count];
int chosen = arc4random() % length;
testo.text = [myArray objectAtIndex: chosen];
}
what I want to do now, is when I open the app and get a random object, to take it out from the list, so that it won't be picked again
ex. I open the app>I get "Pizza">Do the action again>I don't get "Pizza" anymore, only "Pasta" "Wait" and "Go"
What should I do ? Which code should I use ?
Thanks for answers
© Stack Overflow or respective owner