• 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 fasters than the osax
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: Random Numbers fasters than the osax (From: Arthur J Knapp <email@hidden>)

  • Prev by Date: Re: Random Numbers fasters than the osax
  • Next by Date: Re: Random Numbers fasters than the osax
  • Previous by thread: Re: Random Numbers fasters than the osax
  • Next by thread: Re: Random Numbers fasters than the osax
  • Index(es):
    • Date
    • Thread