• 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 without duplicates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Random number generator without duplicates


  • Subject: Re: Random number generator without duplicates
  • From: Daniel Robinson <email@hidden>
  • Date: Thu, 19 Apr 2001 21:43:35 -0400

Scripters,

You can beat the semantics to death, but we're talking about one of two things, A
shuffled list as illustrated in my last post, or a list of randon numbers within
a range.

Below is a script that selects a random number from 1 - 10, does it a thousand
times, and logs the result.

From that result, you can see that Applescript (v 1.6) produces no appreciable
bias.

Regards,

--Dan

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


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 -- (I get it back on the next line)
set ThisNumber to the result + 1 -- (Don't want a zero)
set item ThisNumber of TheList to (item ThisNumber of TheList) + 1
end repeat

TheList


  • Prev by Date: Here's a strange one
  • Next by Date: problem running apple guidebook modules
  • Previous by thread: RE: Here's a strange one
  • Next by thread: Re: Random number generator without duplicates
  • Index(es):
    • Date
    • Thread