2025-12-25

fanf: (Default)

https://dotat.at/@/2025-12-25-shuffle.html

Here's a pearlescent xmas gift for you!

There are four variants of the algorithm for shuffling an array, arising from two independent choices:

  • whether to swap elements in the higher or lower parts of the array
  • whether the boundary between the parts moves upwards or downwards

The variants are perfectly symmetrical, but they work in two fundamentally different ways: sampling or permutation.

The most common variant is Richard Durstenfeld's shuffle algorithm, which moves the boundary downwards and swaps elements in the lower part of the array. Knuth describes it in TAOCP vol. 2 sect. 3.4.2; TAOCP doesn't discuss the other variants.

(Obeying Stigler's law, it is often called a "Fisher-Yates" shuffle, but their pre-computer algorithm is arguably different from the modern algorithm.)

Read more... )

December 2025

S M T W T F S
 123456
78910111213
14151617181920
21222324 252627
28293031   

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated 2025-12-26 06:55
Powered by Dreamwidth Studios