On Apr 14, 2009, at 1:32 PM, Eric E. Dolecki wrote:
My apologies - what I meant to type was that I AM doing this:
int tmp = (arc4random()%10)+1;
while (tmp == activeTarget) {
tmp = (arc4random()%10)+1;
}
activeTarget = tmp;
So, you are generating a random number between 1 and 10, inclusive.
Given the relatively small number of values, a shuffle is a very
appropriate way to generate a non-repeating but otherwise-random
sequence of numbers.
Note that if your only requirement is simply that you don't get the
same number twice in a row, rather than that you want to see all the
numbers in your set of possible values before any number repeats, a
shuffle is overkill. But also note that if _that_ is your requirement
(i.e. "that you don't get the same number twice in a row"), you're not
really dealing with a random sequence, and may in fact have a design
error. :)
Pete
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com