Shuffle
Zeda Thomas (xedaelnara@gmail.com)
Z80 Assembly
213 bytes

===========/
Motivation/
=========/
  I wanted a faster way to shuffle a list. The standard algorithm
in TI-BASIC is to generate a random list, and cosort it with the
list you want to shuffle using SortA( or SortD(. For example, to
shuffle L1:
    rand(dim(L1->L2
    SortA(L2,L1

  Unfortunately, TI's sorting algorithm is quite slow for big
lists, and you have to waste valuable RAM generating a new list.

It turns out there is an in-place algorithm that takes linear time
called the Fisher-Yates algorithm. It's surprisingly easy to
implement in assembly, so I gave it a go! For reference, this
program can shuffle a 999 element list in roughly one second at
6MHz (the regular TI-83+), or even faster on the 15MHz calcs
(83+SE, 84+, 84+SE, and the family). I didn't have enough RAM to
test the standard way on a 999 element list, but on a 499 element
list it took just over 21 seconds at 15MHz


========================/
How to use this program/
======================/
  This program assumes your list is in Ans. Simply run the
following to shuffle Ans:
    Asm(prgmSHUFFLE

  Now Ans contains the shuffled version of the list. It is worth
noting that your list can be real or complex.
                                                                 |