Correct me if I am wrong, but wont this result in the mines being placed in the front more often than not? sort(function() { return math.rand() - .5; }) doesnt result in a truely random distribution.
It evenly distributes over 0-1. Removing .5, just distributes it evenly between -0.5 and +0.5.
Sort basically says >0, the first option should come first and if <0, the second option should come first.
I believe this still maintains a random distribution and is quite a tidy solution. Thoughts?
It can be extremely biased, and the results can depend on the sort algorithm, because what you're randomizing is the comparison results, not the order. Consider insertion sort: https://en.wikipedia.org/wiki/Insertion_sort
As the list is sorted, elements are inserted from the back by finding the first element that the new element is smaller than. The last element to be inserted is the one at the end of the unsorted array, and, with a random comparator, it has a 50% chance of being "larger" than the biggest of the rest of the elements, and thus remaining at the end of the list.
Microsoft used this technique to "randomize" a list of browsers back in 2010, but, when viewing the page in IE, it ended up putting IE in the last position (out of a set of five browsers) 50% of the time: http://www.robweir.com/blog/2010/02/microsoft-random-browser...
It evenly distributes over 0-1. Removing .5, just distributes it evenly between -0.5 and +0.5. Sort basically says >0, the first option should come first and if <0, the second option should come first.
I believe this still maintains a random distribution and is quite a tidy solution. Thoughts?