• 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 number generator -- OS X different
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Random number generator -- OS X different


  • Subject: Re: Random number generator -- OS X different
  • From: Daniel Robinson <email@hidden>
  • Date: Sat, 21 Apr 2001 00:02:05 -0400

Good Evening,

It was brought to my attention by Bill Fancher that when run on OS X,
Script A, posted yesterday, gave skewed results.

After stepping through, I find that the error occurred when OS X rounded
the results to a an integer. In Script B, adding 0.5 to the result
solves the problem.

Regards

--Dan


------------------------------ SCRIPT A
-------------------------------------------

set TheList to {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

set N to the count of items in TheList

repeat 1000 times
random number N - 1
set ThisNumber to the result + 1
set item ThisNumber of TheList to (item ThisNumber of TheList) + 1
end repeat

TheList


--> {1524, 1000, 1017, 1015, 1014, 1026, 977, 930, 1006, 491}

--------------------------------- SCRIPT B
---------------------------------------


set TheList to {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

repeat 100000 times
random number
set ThisNumber to {(the result + 0.05) * 10} as integer
set item ThisNumber of TheList to (item ThisNumber of TheList) + 1
end repeat

TheList

--> {10018, 10107, 10126, 9911, 10072, 10084, 10208, 9843, 9892, 9739}


bill fancher wrote:

> On Friday, April 20, 2001, at 04:41 AM, Daniel Robinson wrote:
>
> > Are you using Applescript before 1.6?
>
> 1.6 on Mac OS X. I tried it a few more times with n=10000. This was
> typical:
>
> {1524, 1000, 1017, 1015, 1014, 1026, 977, 930, 1006, 491}
>
> --
> bill


  • Follow-Ups:
    • Re: Random number generator -- OS X different
      • From: Bill Briggs <email@hidden>
  • Prev by Date: Re: Finder error: AppleEvent timed out
  • Next by Date: Best way to check for hour?
  • Previous by thread: Re: Finder error: AppleEvent timed out
  • Next by thread: Re: Random number generator -- OS X different
  • Index(es):
    • Date
    • Thread