/** * Randomly permutes an array. * In-place, modern version of the Fisher-Yates algorithm. * The default prng is usually (way) to weak for every permutation * to be a possible outcome. */ function shuffle(array) { var n = array.length, k, t; if (n == 0) return false; while (--n) { k = Math.floor(Math.random() * (n+1)); t = array[n]; array[n] = array[k]; array[k] = t; } } var a = new Array(10); for (var i = 0; i < a.length; i++) a[i] = i; shuffle(a); document.writeln('

' + a.join(', ') + '

'); var b = 'Work is the curse of the drinking classes.'.split(/\s+/); shuffle(b); document.writeln('

' + b.join(' ') + '

');