• 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
Re: Random Numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Random Numbers


  • Subject: Re: Random Numbers
  • From: Greg Titus <email@hidden>
  • Date: Wed, 13 Jun 2001 23:50:30 -0700

On Wednesday, June 13, 2001, at 08:26 PM, Michael P. Rogers wrote:

I probably didn't look in the right place, but I can't find anything in Cocoa for using random numbers.

I did a search through the Foundation API reference for random, but didn't find anything useful -- NSRandomSpecifier and NSSet apparently use a random number generator, but don't provide any publicly accessible methods. This is not a definitive answer, but certainly suggestive.

Anyway, all you need to do is call rand() to generate random uniform numbers -- you don't even need to add any headers -- so a class just to wrap around this call would be overkill. Now as for gaussian and other random numbers, well, that would be nice, but perhaps too specialized.

If you need better / different random numbers you can use the code in OFRandom.h/.m in OmniFoundation (http://www.omnigroup.com/community/developer/sourcecode). It provides a high quality nonlinear congruential random number generator and either flat or gaussian distributed random floating point numbers between 0 and 1.

Hope this helps,
--Greg


  • Follow-Ups:
    • Re: Random Numbers
      • From: Brian Howard <email@hidden>
References: 
 >Re: Random Numbers (From: "Michael P. Rogers" <email@hidden>)

  • Prev by Date: Re: Detecting Keydowns
  • Next by Date: Re: How to get selected text in *foreground* application ?
  • Previous by thread: Re: Random Numbers
  • Next by thread: Re: Random Numbers
  • Index(es):
    • Date
    • Thread