On 5 Aug 2009, at 17:54, Agha Khan wrote:

Dear Mahaboob:
Many people have answered this question but I will take this route.

First of all you only have call srandom once in you program. Best place is when you are going to load the object.

While this entire thread should never have been on *COCOA*-dev in the first place (it has nothing to do with Cocoa), I can't really stand by and let your post sit in the list archives unanswered for some poor soul to stumble across.

Not only is your RANDOM_INT() macro problematic (it generates biased results if the range is anything other than a power of 2, and you've used reserved identifiers [you mustn't use anything starting with an "_" in your own code... all such identifiers are reserved for the implementation]), but your shuffle algorithm is about the worst possible also (it produces biased results).

Amazingly I recall reading that one of the on-line gambling websites was actually using that algorithm to shuffle decks of cards(!), which meant it was possible to predict the sequence with some degree of accuracy. Even in a casual computer game, such an algorithm is not good, but if money is involved it might even be illegal.

This is a good page to read on this topic:

  <http://en.wikipedia.org/wiki/Knuth_shuffle>

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________

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

Reply via email to