• 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 14:02:44 -0400

When I dismantled Script A in OS X, it was clear that it was rounding down,
giving a zero result under .5. (0 - 10 instead of 1 - 10)

The original intent of Script A was to see if Applescript randomizer return
was returning an evenly distributed set. (It did.)

It was noticed that when run in OS X it was skewed. with register one giving
150% and register ten 50%

I wasn't trying to duplicate or speed the process in Script B, merely
illustrate (a) WHY Script A had acted differently in OS X and (b) that it
was still operating without a bias . . . just a skew.

The end result is that if you are using random numbers in your scripts, this
is something about which you should be aware.

-- Dan

------------------------------------------------------------------------

Bill Briggs wrote:

>I don't think that's what's going on. Take a look at the two scripts very
closely.

>
> >------------------------------ 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}
> _______________________________________________


References: 
 >Re: Random number generator -- OS X different (From: Daniel Robinson <email@hidden>)
 >Re: Random number generator -- OS X different (From: Bill Briggs <email@hidden>)

  • Prev by Date: Re: Random number generator -- OS X different
  • Next by Date: Re: Setting the startup disk.
  • Previous by thread: Re: Random number generator -- OS X different
  • Next by thread: Re: Random number generator -- OS X different
  • Index(es):
    • Date
    • Thread