int i;
for (i = 0; i < high - low; i++)
{
int index = low - 1;
while (![source containsIndex:index])
{
index = some random index; //I'll leave it to you to pick which
random generator you want.
}
[source removeIndex:index];
[list addObject:[NSNumber numberWithInt:index]]; //NSNumber is a
better container for this than NSString and you can always convert
with -stringValue
}
On Jul 13, 2006, at 7:46 AM, Bobby B wrote:
Hey guys,
I'm trying to write a way to generate a random array of X numbers, and
the numbers need to be between 0 and X, and not be repeating (its for
generating a random playlist.)
I've come up with the following, which works perfectly. I'm just
curious if there is a "much better way" to do this? (Oh, and I want
the numbers to be strings in the array)..
if (!([randomArray containsObject:@"-"])) finished = YES;
}
NSLog(@"%@", randomArray);
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden
This email sent to email@hidden