JavaScript: Do I need a recursive function to solve this problem?
<p>In this fiddle <a href="http://jsfiddle.net/5L8Q8/28/" rel="nofollow">http://jsfiddle.net/5L8Q8/28/</a>, if you click the black button, it randomly selects one of two values (red or blue) from an array. The randomly selected value is assigned to <code>ran</code>. In my real life application, there will be 16 elements in that array. </p>

<p>If you the pink "playagain" button, it chooses a random element from the same array but I want to make sure it's not the same one chosen as last time. </p>

<p>Therefore, when I click <code>playagain</code>, I assign <code>ran</code> to <code>lastran</code> and compare it to the next randomly chosen value from the array and, if they are the same, choose randomly again. However, the way I have it isn't guaranteeing that (upon the completion of <code>playagain</code>) <code>ran</code> is different. </p>

<p>I think I need a recursive function where comment 2 is in the code below, but I keep breaking my code when I try to create it. </p>

<p>Can you comment on the 3 comments in the code below? </p>

<p>Note, I'm a relative newbie, so this code is probably awful...</p>

<pre><code>$("#playagain").click(function(){
    lastran = ran; 


    ran = getRandom(myArray, true);

    if (ran === lastran) { 

        ran = getRandom(myArray, true); //1. do I need to return this?

           //2. want to test ran === lastran again.. How to set up recursive function?

    } else {

       return; //3.is this the right thing to do here?
    }  

});
</code></pre>
