home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / SHUFFLE.ICN < prev    next >
Text File  |  1991-07-13  |  963b  |  37 lines

  1. ############################################################################
  2. #
  3. #    Name:     shuffle.icn
  4. #
  5. #    Title:     Shuffle values
  6. #
  7. #    Author:     Ward Cunningham and Ralph E. Griswold
  8. #
  9. #    Date:     February 22, 1990
  10. #
  11. ############################################################################
  12. #  
  13. #     The procedure shuffle(x) shuffles a string or list. In the case
  14. #  that x is a string, a corresponding string with the characters
  15. #  randomly rearranged is produced. In the case that x is a list,
  16. #  the values in the list are randomly rearranged.
  17. #  
  18. ############################################################################
  19.  
  20. procedure shuffle(x)
  21.    local i
  22.  
  23.    x := string(x)        # may fail
  24.    every i := *x to 2 by -1 do
  25.       x[?i] :=: x[i]
  26.    return x
  27. end
  28.  
  29. #  Note:  the following procedure is simpler, but does not produce
  30. #  as good a shuffle:
  31. #
  32. #procedure shuffle(x)
  33. #   x := string(x)
  34. #   every !x :=: ?x
  35. #   return x
  36. #end
  37.