元の配列に偶数のElemnetがあると仮定します。
NSMutableArray *list1 = [[NSMutableArray alloc] init];
NSMutableArray *list2 = [[NSMutableArray alloc] init];
NSMutableArray *originalArray = [[NSMutableArray alloc] initWithObjects:@"ssjsf1",@"ssjsf2",@"ssj3sf",@"ssj4sf",@"ss5jsf",@"ssj6sf",@"ssj7sf",@"ssj8sf",@"ssj9sf",@"s10sjsf",@"ss11jsf",@"ss12jsf",@"ss12jsf",@"ss12jsf",nil];
NSMutableArray *temp = [[NSMutableArray alloc] init];
int i =0;
for (i = 0; [temp count] < [originalArray count] ; i++){
int r = arc4random_uniform([originalArray count]);
if(!([temp containsObject:[NSNumber numberWithInt:r]]))
{
[temp addObject:[NSNumber numberWithInt:r]];
[list1 addObject:[originalArray objectAtIndex:r]];
if([originalArray count] % 2 == 0)
{
if([list1 count] > ([originalArray count]/2) )
{
[list1 removeObjectAtIndex:r];
[temp removeObject:[NSNumber numberWithInt:r]];
}
}
if([originalArray count] % 2 != 0)
if([list1 count] > ([originalArray count]/2 + 1) )
{
[list1 removeObjectAtIndex:r];
[temp removeObject:[NSNumber numberWithInt:r]];
}
}
r = arc4random_uniform([originalArray count]);
if(!([temp containsObject:[NSNumber numberWithInt:r]]))
{
[temp addObject:[NSNumber numberWithInt:r]];
[list2 addObject:[originalArray objectAtIndex:r]];
if([originalArray count] % 2 == 0)
{
if([list2 count] > ([originalArray count]/2) )
{
[list1 removeObjectAtIndex:r];
[temp removeObject:[NSNumber numberWithInt:r]];
}
}
if([originalArray count] % 2 != 0)
if([list2 count] > ([originalArray count]/2) )
{
[list2 removeObjectAtIndex:r];
[temp removeObject:[NSNumber numberWithInt:r]];
}
}
}
NSLog(@"List1 -- %@ \n List 2 --- %@",list1, list2);
これがお役に立てば幸いです。