Algorithmica (1998) 21: 2–20
Algorithmica
© 1998 Springer-Verlag New York Inc.
Fast Generation of Random Permutations
Via Networks Simulation
1
A. Czumaj,
2
P. Kanarek,
3
M. Kuty lowski,
2
and K. Lory´ s
4
Abstract. We consider the problem of generating random permutations with uniform distribution. That is,
we require that for an arbitrary permutation π of n elements, with probability 1/n! the machine halts with the
i th output cell containing π(i ), for 1 ≤ i ≤ n. We study this problem on two models of parallel computations:
the CREW PRAM and the EREW PRAM.
The main result of the paper is an algorithm for generating random permutations that runs in O(log log n)
time and uses O(n
1+o(1)
) processors on the CREW PRAM. This is the first o(log n)-time CREW PRAM
algorithm for this problem.
On the EREW PRAM we present a simple algorithm that generates a random permutation in time O(log n)
using n processors and O(n) space. This algorithm outperforms each of the previously known algorithms for
the exclusive write PRAMs.
The common and novel feature of both our algorithms is first to design a suitable random switching network
generating a permutation and then to simulate this network on the PRAM model in a fast way.
Key Words. Parallel algorithms, Random permutation, Uniform distribution, Switching networks, Matching,
PRAM, CREW, EREW.
1. Introduction. Generating permutations is a fundamental problem already studied
in theoretical and applied computer science for a few decades. One approach (historically
first) assumed generation of all permutations of n elements (see [8] and [17], and the
references therein). Evidently, the problem is intractable even for very moderate values
of n. The next approach, also extensively investigated, is generating permutations at
random. This task can be formally described as follows:
DEFINITION 1. A machine M generates a permutation π of n elements, if, when halted,
the output memory cells Z
1
,..., Z
n
store, respectively, π(1),...,π(n). We say that M
generates (uniformly) random permutations of n elements, if for every permutation π
of n elements M generates π with probability 1/ n!.
1
This research was partially supported by KBN Grant 8 S503 002 07, EU ESPRIT Long Term Research
Project 20244 (ALCOM-IT), DFG-Sonderforschungsbereich 376 “Massive Parallelit¨ at,” and DFG Leibniz
Grant Me872/6-1. A preliminary version appeared in Proceedings of the 4th Annual European Symposium on
Algorithms (ESA ’96), volume 1136 of Lecture Notes in Computer Science, pages 246–260, Springer-Verlag,
Berlin, 1996.
2
Heinz Nixdorf Institute and Department of Mathematics and Computer Science, University of Paderborn,
D-33095 Paderborn, Germany. {artur,mirekk}@uni-paderborn.de.
3
Institute of Computer Science, University of Wroc law, Przesmyckiego 20, PL-51-151 Wroc law, Poland.
pka@tcs.uni.wroc.pl.
4
Department of Computer Science, University of Trier, D-54286 Trier, Germany, and Institute of Computer
Science, University of Wroc law, Przesmyckiego 20, PL-51-151 Wroc law, Poland. lorys@tcs.uni.wroc.pl.
Received November 1996; revised March 1997. Communicated by J. D´ ıaz and M. J. Serna.