home *** CD-ROM | disk | FTP | other *** search
- ############################################################################
- #
- # File: shuffle.icn
- #
- # Subject: Procedures to shuffle values
- #
- # Author: Ward Cunningham and Ralph E. Griswold
- #
- # Date: February 22, 1990
- #
- ###########################################################################
- #
- # The procedure shuffle(x) shuffles a string or list. In the case
- # that x is a string, a corresponding string with the characters
- # randomly rearranged is produced. In the case that x is a list,
- # the values in the list are randomly rearranged.
- #
- ############################################################################
-
- procedure shuffle(x)
- local i
-
- x := string(x) # may fail
- every i := *x to 2 by -1 do
- x[?i] :=: x[i]
- return x
- end
-
- # Note: the following procedure is simpler, but does not produce
- # as good a shuffle:
- #
- #procedure shuffle(x)
- # x := string(x)
- # every !x :=: ?x
- # return x
- #end
-