I want to show array objects at the same time in different 10 labels. They should be align random for every time. How can I do that?
I’ve done the random part:
srandom(time(NULL));
NSUInteger arr = [myarray count];
for (NSUInteger i = 0; i < arr; ++i) {
int nElements = arr - i;
int n = (random() % nElements) + i;
[myarray exchangeObjectAtIndex: i withObjectAtIndex:n];
}
But when I want to use the code below to 10 different labels, array objects repeat, and 2 or 3 different labels can have the same value. How can I make them different?
myLabel.text = [NSString stringWithFormat:@"%@", [[arr objectAtIndex:(random()%9)+1]intValue];
Thanks
As you are uses the random() method to randomise the objects into array then no need to use the random() for displaying the data in labels as in randome method some returned data can be repeatedly returned so this happens just use random() for randomize the data and serially show them in labels using simple for loop.