Closed mratsim closed 5 years ago
Not sure I understand; how does this accomplish the property that you can compute any arbitrary value in the shuffling in O(1) time? This seems like an incremental approach that requires computing the 1...n'th values before you can compute the n+1'th.
That was actually sparked when you were looking into the prime shuffle but it was quite slow. So I researched alternatives. However the Feistel shuffle that was proposed within the same day definitely supersedes this one.
This adds another shuffling alternative that was taken from natural language processing.
Papers:
A New Data Structure for Cumulative Frequency Tables
The algorithm is also described in this blog post Heaps for incremental computation with an alternative Python implementation using 1-based indexing (and 2x more memory if n is a power of 2).
Bench on my machine: