Thursday, January 24, 2008

randomly sorting lists

Was hashing out a very quick program to take a list of maps from a file and to replace the ones in the config file with those but sorted into a fairly random pattern.


Then I realized that I have no bloody idea how to randomly sort, ehh unsort a list of strings.


My notes scribbled in file:
##################################################
# Randomize the contents of a list -- algorithmic ideas
#
# input; list of N items to be randomized
# storage: table T to hold previously generated random numbers
#
# loop until done where each item in list is sorted into new list
#   generate random number R between 0 and N
#   store N in a table T if not already done so then
#     if N is not in table T
#       new list[R] = current item in loop
#     else if N is in table continue to next iteration
#
# List will probably have to be a temporary to be generated from input list
#
# result expected: loop once per each item in the input list creating
#    


That is the best I can think of when you consider the number of distractions:

birds screeching
mother shouting (at me, dog, and bird)
dozen pans falling
going AFK every X minutes
walking out in the cold to check the car cover
sorting pans back onto shelf
et alii

Is it a wonder I *usually* don't touch an ounce of code until I am THE ONLY MORON AWAKE in this house ? I think not !

No comments:

Post a Comment