Re: Random sorting
Re: Random sorting
- Subject: Re: Random sorting
- From: "John C. Randolph" <email@hidden>
- Date: Mon, 6 Jan 2003 14:01:30 -0800
On Monday, January 6, 2003, at 01:25 PM, Ben Dougall wrote:
Some years ago I worked on a card game and what we did was not to
shuffle the array but rather pick random values out of the array.
The card-dealing algorithm was:
pick a random number in the range of 0 to the number of cards.
Choose the card in that slot.
take the last card, and put it in the slot you just picked.
The first time, you pick a number from 0 to 51. The next time, you
pick a number from 0 to 50, and so on.
but surely that will allow you to pick the same thing twice, which
isn't what's wanted here?
No, the pile shrinks as you remove each card.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.