Possible Duplicate:
How to randomize a javascript array?
I am writing a code in JavaScript in which I need to take 35 input values, assign each of them a place in an array, then shuffle them such that they will be rearranged in a different order. As such:
var sort = new Array(35);
sort[0] = document.getElementById("d1p1").value;
sort[1] = document.getElementById("d1p2").value;
// ...
// ... (till 35)
var rand1 = Math.floor(Math.random() * 35);
var rand2 = Math.floor(Math.random() * 35);
// ...
// ... (till 35)
var rsort = new Array(35);
rsort[rand1] = document.getElementById("d1p1").value;
rsort[rand2] = document.getElementById("d1p2").value;
The only problem is that since Math.floor(Math.random()*35) generates some of the same numbers from 1-35 more than once (well, I guess that is the point of randomness), then two values are sometimes assigned the same input box and they return undefined. Any ideas?