|
|
|
|
|
by deadbeef404
3840 days ago
|
|
> 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? |
|
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...