• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[OT] Re: Generating random numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[OT] Re: Generating random numbers


  • Subject: [OT] Re: Generating random numbers
  • From: Alastair Houghton <email@hidden>
  • Date: Wed, 5 Aug 2009 22:00:58 +0100

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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >Generating random numbers (From: Mahaboob <email@hidden>)
 >Re: Generating random numbers (From: Agha Khan <email@hidden>)

  • Prev by Date: Re: How do I compute the screen width of a particular font?
  • Next by Date: Re: How do I compute the screen width of a particular font?
  • Previous by thread: Re: Generating random numbers
  • Next by thread: Re: Generating random numbers
  • Index(es):
    • Date
    • Thread