generate unique random numbers in javacript
<p>I am trying to generate a set of random unique numbers as shown in my code below:</p>

<pre><code>if(document.getElementsByTagName("a")!=null&amp;&amp;document.getElementsByTagName("a").length&gt;0){
        var titleArray=newArray();
        var urlArray=newArray();
        var j=0;

        var arr = [];

        for(i=1;i&lt;document.getElementsByTagName("a").length;i++){

            var anchorLength = document.getElementsByTagName("a").length ;

            var randNumber=Math.floor(Math.random()*anchorLength);
            var found=false;
            for(var k=0;k&lt;arr.length;k++){
            if(arr[k]==randNumber  ){
                found=true;
                break;
            }
            }

            if (!found &amp;&amp; randNumber!=0) {
                arr[arr.length] = randNumber;
                var uniqueRandNumber = randNumber;

            }
            else{   
            continue;
            }



            if(document.getElementsByTagName("a")[uniqueRandNumber].title!=null&amp;&amp;document.getElementsByTagName("a")[uniqueRandNumber].title!=""){

                j++;
                if (j &lt; 36) {
                    urlArray[j] = document.getElementsByTagName("a")[uniqueRandNumber].href;
                    titleArray[j] = document.getElementsByTagName("a")[uniqueRandNumber].title;
                }

            }
        }
    }


    myWindow=window.open('http://inside-files.mathworks.com/public/Sathish_Balu/faces/faces.html?faces&amp;titles='+titleArray+',&amp;url='+urlArray);
    myWindow.focus();}
</code></pre>

<p>What happens here is, its entering the if loop less than exact number of times it should actually enter .. can some1 help me in this ?</p>
