Re: Random Numbers
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