Yeah I knew that before in the days that I made c programs but it been so long that I forgot.

On May 8, 2008, at 6:57 AM, Gregory Weston wrote:

Since neither the question nor the answer is particularly Cocoa- related, I'm following up off-list. I just wanted to make sure that you understood that using % to scale your raw result into the range you want messes with the uniformity of the sequence. Consider, as a degenerate case, that you had a random number generator that gave you back a number from 0 to 15 and you wanted a number between 0 and 11. If you did RND % 12, 0-3 will show up twice as often as any other result. The closer the range of the random function is to an integer multiple of the range you actually want, the less absolute impact that has but there will almost always be some skewing introduced. To alleviate that, you want to scale the raw result to a number in [0,1), multiply that by the range of your desired result and then add your minimum.

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to