Playing random songs algorithm
<p>Wondering what is the best way to solve this problem: Random play a song from a list of given songs in such a way that no songs is repeated until all the songs are played.</p>

<p>My algorithm basically calls get_random with the reduced set of music sets to find out the next song to play. get_random uses power of 2 to divide the list and then further sub-dividing.</p>

<p>Is this the best I can do or any other better algorithms I can come up with? I need just the idea.</p>

<pre><code>import random
import math

def get_random(number):
        if number == 0:
            return number
        if number == 1:
            return number
        #make the number power of 2
        orig_no = number
        number = 1 &lt;&lt; (math.floor(math.log(number))+1)
        left = 0
        right = number
    # check if toss falls in this current half and then change the half for next recursion. 
    # we change half from 1, 2, 4, 8, 16, 36, 64, 128
        while left &lt; right:
          #f1 can be replaced by this rd.randint(0, 1)
            toss_value = f1() 
            if toss_value:
                right = math.floor((left + right)/2)
            else:
                left = math.floor((left + right)/2) + 1
        if left &gt;= orig_no:
            return get_random(orig_no)
        else:
            return left

songs = ["i am here", "your are beautiful", "soorry", "i am happy", "where am i", "what did i do", "nothing wrong with you"]
for i in range(0, len(songs)-1):
        value = get_random(len(songs))
        print(songs[value])
        songs.pop(value)
</code></pre>