• 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: Setting a list to a random order
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting a list to a random order


  • Subject: Re: Setting a list to a random order
  • From: Michelle Steiner <email@hidden>
  • Date: Mon, 23 May 2005 12:42:05 -0700

On May 23, 2005, at 12:23 PM, Steve Suranie wrote:

I have to read items from a file which are listed in a sequential order and
randomize them - They appear in the file like this.


6510001460    1    14    $2 coupon
1410011417    2    14    $2 coupon
1210021412    3    14    $2 coupon
1910031454    4    14    $2 coupon

does anyone have a snippet of code that will shuffle a list?

set a to "6510001460 1 14 $2 coupon 1410011417 2 14 $2 coupon 1210021412 3 14 $2 coupon 1910031454 4 14 $2 coupon"

set b to paragraphs of a
set x to {}
set c to {}

repeat until (count of c) is (count of b)
    set rnd to random number from 1 to count of b
    if rnd is not in x then
        copy item rnd of b to end of c
        copy rnd to x
    end if
end repeat
c
set text item delimiters to return
set d to c as text
set text item delimiters to ""
d



--
Windows was always a mystery to me; the biggest mystery being "Why does anyone want to use this?"


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Text delineation and mac addresses
  • Next by Date: Fwd: Setting a list to a random order
  • Previous by thread: Text delineation and mac addresses
  • Next by thread: Fwd: Setting a list to a random order
  • Index(es):
    • Date
    • Thread