• 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: Paul Berkowitz <email@hidden>
  • Date: Tue, 17 Apr 2001 19:43:11 -0700

On 4/17/01 6:27 PM, "Michelle Steiner" <email@hidden> wrote:

> On 4/17/01 2:56 PM, Chris Espinosa <email@hidden> wrote:
>
>> If you want a guaranteed nonrepeating cycle, you have to shuffle (as
>> already mentioned). A shuffling algorithm looks like this:
>
> That's very nice; it's going into my library. To get six random numbers
> out of fifty six, you'd call the handler with something like this, right?
>
> items 1 through 6 of create_shuffled_list(56) It really doesn't matter
> which six items are used because they're in random order, so the first
> six are as good as any.
>

If that's the case (and I'm not yet 100% certain that it is) then you don't
have to get all 56 items shuffled. Just stop when you hit no. 6 :


to create_shuffled_sublist(totalNumberSet, listLength)
set orderedList to {}
repeat with n from 1 to totalNumberSet
set end of orderedList to n
end repeat
set shuffledList to {}
repeat listLength times
set chosenItem to 0
repeat until chosenItem is not 0
set chosenItem to some item of orderedList
end repeat
set end of shuffledList to chosenItem
set item chosenItem of orderedList to 0
end repeat
return shuffledList
end create_shuffled_sublist


create_shuffled_sublist(56, 6)
-- {38, 13, 32, 52, 40, 8}


References: 
 >Re: Random number generator without duplicates? (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: PreFab's ability to set a default directory ...
  • Next by Date: Re: How to script URL Access to post radio buttons?
  • Previous by thread: Re: Random number generator without duplicates?
  • Next by thread: Re: Random number generator without duplicates?
  • Index(es):
    • Date
    • Thread