Often I want to show data in random order. Sometimes I just want to pick a few random things out of many. Just as often I want to show all of the information, but in a randomized order, similar to shuffling a deck of cards. To do this we can use the JavaScript sorting algorithm in combination with a customized sorting comparison function that will randomize the sorted order.
The comparison function returns a value greater than zero or less than zero depending on which element should be sorted first. When the sorting algorithm is executed the data will be randomized if the comparison function gives each comparison of elements an equal probability of being greater than zero or less than zero.
<script type="text/javascript">
randomComparison = function(a, b) {
return Math.random()-.5;
};
domainList.sort(randomComparison);
showList(domainList);
</script>