TravisMath
08-25-2005, 03:58 AM
I need help on learning how to take an array and basically put everything in that array in random order without repeating any part of the array. So if someone could basically just show me how to take a group of variables and randomize them and relisting them in the random order it would help. Thanks!
<script type="text/javascript">
var a=[12,3,5,78,7,10,32,41,100,13];//the genuine array
var r;
function ran(){
r = new Array();// the randomized array
for(var i=0;i<a.length;i++){
r[i] = a[Math.floor(Math.random()*a.length)];
var comp = r[i];
for(var j=0;j<r.length-1;j++){
if(comp==r[j]){i--;break}
}
}
}
onload=function(){ran();alert(r)}
</script>
Need some explanation?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.