Re: Random Numbers fasters than the osax
Re: Random Numbers fasters than the osax
- Subject: Re: Random Numbers fasters than the osax
- From: email@hidden (Michael Sullivan)
- Date: Mon, 1 Apr 2002 21:25:22 -0500
- Organization: Society for the Incurably Pompous
Arthur J. Knapp writes:
>
> I think you mean:
>
>
>
> (R mod (M - N + 1)) + N
>
I don't think so? Can you provide an example where (R mod M) + N would
>
not return a number from N to M,
Sure. M is 50, N is 10 and R is 48.
when R is any number such that
(R mod M) > (M - N)
then
(R mod M) + N
will be greater than both M and N.
>
(or why (R mod (M - N + 1)) + N is better)?
Because it always returns a number between M and N inclusive (assuming M
>
N), and your formula does not.
Think about it. a mod b will return an integer between zero and b-1.
So R mod M, returns a number between zero and M - 1. Add N to that
number, and you end up with an integer between N and M - 1 + N.
OTOH, R mod (M-N+1) returns a number between zero and (M - N +1) -1,
which is M - N. Add N, and you get a lower bound of zero + N == N, and
an upper bound of (M - N) + N == M.
Michael
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.