メインコンテンツまでスキップ
バージョン:25.2

shuffle, shuffled

  • function
  • command
  • new in 2.03
  • The shuffle function returns a string or a list in a random order. If shuffle is called with a parameter that is a list, the value returned will be a list of the same values in a random order. Otherwise the parameter is treated as a string and the characters of the string are shuffled randomly:
         put shuffle("ABCD") —> "DBAC"
put the shuffle of [1,2,3,4,5,6] —> [5,1,3,6,4,2]
put raffleTickets.shuffle into hopper

    The function can also be called using a shuffled or in shuffled order or in random order syntax:

         put [jack,queen,king,ace] shuffled —> ["ace","queen","king","jack"]
put "ridiculous" in a random order —> "uiiuodlcsr"


  • The shuffle command will shuffle the elements of a container. If called with a variable or other container, its contents are shuffled directly. Otherwise the result of the shuffle operation is assigned to the variable it:
         set myList to [3,4,5,6,7,8]
shuffle myList
put myList —> [4,6,5,8,3,7]
shuffle [1,3,5,7,9] — (not a container, so result goes into 'it')
put it —> [7,1,5,9,3]
  • Related: reverse