English

MergeShuffle: A Very Fast, Parallel Random Permutation Algorithm

Data Structures and Algorithms 2015-08-14 v1 Discrete Mathematics

Abstract

This article introduces an algorithm, MergeShuffle, which is an extremely efficient algorithm to generate random permutations (or to randomly permute an existing array). It is easy to implement, runs in nlog2n+O(1)n\log_2 n + O(1) time, is in-place, uses nlog2n+Θ(n)n\log_2 n + \Theta(n) random bits, and can be parallelized accross any number of processes, in a shared-memory PRAM model. Finally, our preliminary simulations using OpenMP suggest it is more efficient than the Rao-Sandelius algorithm, one of the fastest existing random permutation algorithms. We also show how it is possible to further reduce the number of random bits consumed, by introducing a second algorithm BalancedShuffle, a variant of the Rao-Sandelius algorithm which is more conservative in the way it recursively partitions arrays to be shuffled. While this algorithm is of lesser practical interest, we believe it may be of theoretical value. Our full code is available at: https://github.com/axel-bacher/mergeshuffle

Keywords

Cite

@article{arxiv.1508.03167,
  title  = {MergeShuffle: A Very Fast, Parallel Random Permutation Algorithm},
  author = {Axel Bacher and Olivier Bodini and Alexandros Hollender and Jérémie Lumbroso},
  journal= {arXiv preprint arXiv:1508.03167},
  year   = {2015}
}

Comments

Preliminary draft. 12 pages, 1 figure, 3 algorithms, implementation code at https://github.com/axel-bacher/mergeshuffle

R2 v1 2026-06-22T10:32:49.831Z