var a = [1,2,3,4,5]; for ( var i = a.length; i-->0; ) { var t = a[i], j = Math.floor(i*Math.random()); a[i] = a[j]; a[j] = t; } alert(a)