             else
                 msg.send "Invalid selection: invalid nomination index"
         else
-            msg.send "Invalid selection: missing nomination index"
+            selected = @storage.nominations[Math.floor(Math.random() * @storage.nominations.length)]
+            try
+                @storage.history.push selected
+            catch
+                @storage.history = []
+                @storage.history.push selected
+            finally
+                @storage.nominations = []
+                @save
+                msg.send "Randomly selected #{selected["url"]}, nominated by #{selected["user"]}"
 
 module.exports = (robot) ->
 

    nominate: (msg) ->
        if msg.match[1] != ""
            url = msg.match[2]
            urlPattern = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[.\!\/\\w]*))?)/ig
            # To be implemented in a future release
            # spotify = /https?:\/\/(open|play)\.spotify\.com\/(album|track|user\/[^\/]+\/playlist)\/([a-zA-Z0-9]+)/
            # googlePlay = /https?:\/\/(music|play)\.google\.com\/music\/m\/([a-zA-Z0-9]+)/
            # youtube = /https?:\/\/(?:www\.)?youtube.com\/watch\?(?=.*v=\w+)(?:\S+)?/
            if url.match urlPattern
                user = msg.message.user.name.toLowerCase()
                try
                    @storage.nominations.push(user: user, url: msg.match[2])

#   aotw nominate <url> - nominate an album *
#   aotw nominations [length] - view all current nominations, optionally limited to [length] *
#   aotw reset - reset all AOTW data *~
#   aotw select [nomination index] - select the AOTW (of given index or random) and reset nominations *~
#
# Author:
#   Thomas Gaubert
