• 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: Thu, 6 Aug 2009 17:44:02 +0100

On 6 Aug 2009, at 17:21, Mac First wrote:

Not strictly Cocoa, but a trick I recently incorporated to remove the mod-bias is (email code):

float frand = (random() * 1.0) / (RAND_MAX * 1.0); // gives 0.0-0.99999...
int myRand = frand * 15; // to get a number from 0-14, inclusive.

That isn't completely unbiased either. It is an *improvement*, to be sure (though you could do the same thing with integers rather than resorting to floating-point). (Take a look at the link I posted previously where it discusses this technique also.)


And as for "Not strictly Cocoa", this entire thread is "Not strictly Cocoa", as I may already have mentioned...

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: 
 >Re: Generating random numbers (From: Mahaboob <email@hidden>)
 >Re: Generating random numbers (From: Jeremy Pereira <email@hidden>)
 >Re: Generating random numbers (From: Mac First <email@hidden>)

  • Prev by Date: Re: [iPhone] Webview stringByEvaluatingJavaScriptFromString
  • Next by Date: Change Opacity of Image
  • Previous by thread: Re: Generating random numbers
  • Next by thread: How can we distinguish which alert we are talking about?
  • Index(es):
    • Date
    • Thread