Meat Draft: Random Order

The Draft Order is determined by shuffling an array which contains all selected teams.

The shuffle algorithm works by starting with the last element and randomly choosing another element to swap it with.

It then moves to the second-to-last element, choosing randomly from among elements to its left.

The random element could be the same one, so it would remain in its original order.

The process continues until there are no elements left of the current item.

As the algorithm proceeds, the chance of swapping an item with itself rises

Until there is only one element left, and it can choose only itself.


This is the function which implements the algorithm. You can find it in the draftfunctions.js file. It is executed every time the participating teams are changed. Once a draft it started, that displayed order is saved in the database and locked as shown on screen.

Sample:

This page runs a similar function with added code to show the process in text. Click on team check boxes to see how the randomized list is generated with each change.

It lists the current team order at every step showing the current item in black and the random item to swap with in purple. (unless it picks itself, then there is no purple item)

You can press F12 and set a breakpoint at line 77 to step through the shuffle() function on this page.