HOME

TheInfoList



OR:

A random permutation is a
random In common usage, randomness is the apparent or actual lack of pattern or predictability in events. A random sequence of events, symbols or steps often has no order and does not follow an intelligible pattern or combination. Individual ran ...
ordering of a set of objects, that is, a
permutation In mathematics, a permutation of a set is, loosely speaking, an arrangement of its members into a sequence or linear order, or if the set is already ordered, a rearrangement of its elements. The word "permutation" also refers to the act or pro ...
-valued
random variable A random variable (also called random quantity, aleatory variable, or stochastic variable) is a mathematical formalization of a quantity or object which depends on random events. It is a mapping or a function from possible outcomes (e.g., the po ...
. The use of random permutations is often fundamental to fields that use
randomized algorithm A randomized algorithm is an algorithm that employs a degree of randomness as part of its logic or procedure. The algorithm typically uses uniformly random bits as an auxiliary input to guide its behavior, in the hope of achieving good performa ...
s such as
coding theory Coding theory is the study of the properties of codes and their respective fitness for specific applications. Codes are used for data compression, cryptography, error detection and correction, data transmission and data storage. Codes are studied ...
,
cryptography Cryptography, or cryptology (from grc, , translit=kryptós "hidden, secret"; and ''graphein'', "to write", or '' -logia'', "study", respectively), is the practice and study of techniques for secure communication in the presence of adv ...
, and
simulation A simulation is the imitation of the operation of a real-world process or system over time. Simulations require the use of Conceptual model, models; the model represents the key characteristics or behaviors of the selected system or proc ...
. A good example of a random permutation is the
shuffling Shuffling is a procedure used to randomize a deck of playing cards to provide an element of chance in card games. Shuffling is often followed by a cut, to help ensure that the shuffler has not manipulated the outcome. __TOC__ Techniques Over ...
of a
deck of cards A playing card is a piece of specially prepared card stock, heavy paper, thin cardboard, plastic-coated paper, cotton-paper blend, or thin plastic that is marked with distinguishing motifs. Often the front (face) and back of each card has a fi ...
: this is ideally a random permutation of the 52 cards.


Generating random permutations


Entry-by-entry brute force method

One method of generating a random permutation of a set of length ''n'' uniformly at random (i.e., each of the ''n''!
permutation In mathematics, a permutation of a set is, loosely speaking, an arrangement of its members into a sequence or linear order, or if the set is already ordered, a rearrangement of its elements. The word "permutation" also refers to the act or pro ...
s is equally likely to appear) is to generate a
sequence In mathematics, a sequence is an enumerated collection of objects in which repetitions are allowed and order matters. Like a set, it contains members (also called ''elements'', or ''terms''). The number of elements (possibly infinite) is called ...
by taking a random number between 1 and ''n'' sequentially, ensuring that there is no repetition, and interpreting this sequence (''x''1, ..., ''x''''n'') as the permutation : \begin 1 & 2 & 3 & \cdots & n \\ x_1 & x_2 & x_3 & \cdots & x_n \\ \end, shown here in two-line notation. This brute-force method will require occasional retries whenever the random number picked is a repeat of a number already selected. This can be avoided if, on the ''i''th step (when ''x''1, ..., ''x''''i'' − 1 have already been chosen), one chooses a number ''j'' at random between 1 and ''n'' − ''i'' + 1 and sets ''x''''i'' equal to the ''j''th largest of the unchosen numbers.


Fisher-Yates shuffles

A simple
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for performing ...
to generate a permutation of ''n'' items uniformly at random without retries, known as the Fisher–Yates shuffle, is to start with any permutation (for example, the
identity permutation In mathematics, a permutation group is a group ''G'' whose elements are permutations of a given set ''M'' and whose group operation is the composition of permutations in ''G'' (which are thought of as bijective functions from the set ''M'' to i ...
), and then go through the positions 0 through ''n'' − 2 (we use a convention where the first element has index 0, and the last element has index ''n'' − 1), and for each position ''i'' swap the element currently there with a randomly chosen element from positions ''i'' through ''n'' − 1 (the end), inclusive. It's easy to verify that any permutation of ''n'' elements will be produced by this algorithm with probability exactly 1/''n''!, thus yielding a uniform distribution over all such permutations. unsigned uniform(unsigned m); /* Returns a random integer 0 <= uniform(m) <= m-1 with uniform distribution */ void initialize_and_permute(unsigned permutation[], unsigned n) Note that if the uniform() function is implemented simply as random() % (m) then a bias in the results is introduced if the number of return values of random() is not a multiple of m, but this becomes insignificant if the number of return values of random() is orders of magnitude greater than m.


Statistics on random permutations


Fixed points

The
probability distribution In probability theory and statistics, a probability distribution is the mathematical function that gives the probabilities of occurrence of different possible outcomes for an experiment. It is a mathematical description of a random phenomenon ...
of the number of fixed points in a uniformly distributed random permutation approaches a
Poisson distribution In probability theory and statistics, the Poisson distribution is a discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time or space if these events occur with a known co ...
with
expected value In probability theory, the expected value (also called expectation, expectancy, mathematical expectation, mean, average, or first moment) is a generalization of the weighted average. Informally, the expected value is the arithmetic mean of a ...
1 as ''n'' grows. In particular, it is an elegant application of the
inclusion–exclusion principle In combinatorics, a branch of mathematics, the inclusion–exclusion principle is a counting technique which generalizes the familiar method of obtaining the number of elements in the union of two finite sets; symbolically expressed as : , A \cu ...
to show that the probability that there are no fixed points approaches 1/''e''. When ''n'' is big enough, the
probability distribution In probability theory and statistics, a probability distribution is the mathematical function that gives the probabilities of occurrence of different possible outcomes for an experiment. It is a mathematical description of a random phenomenon ...
of fixed points is almost the
Poisson distribution In probability theory and statistics, the Poisson distribution is a discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time or space if these events occur with a known co ...
with
expected value In probability theory, the expected value (also called expectation, expectancy, mathematical expectation, mean, average, or first moment) is a generalization of the weighted average. Informally, the expected value is the arithmetic mean of a ...
1. The first ''n'' moments of this distribution are exactly those of the Poisson distribution.


Randomness testing

As with all random processes, the quality of the resulting distribution of an implementation of a randomized algorithm such as the Knuth shuffle (i.e., how close it is to the desired uniform distribution) depends on the quality of the underlying source of randomness, such as a
pseudorandom number generator A pseudorandom number generator (PRNG), also known as a deterministic random bit generator (DRBG), is an algorithm for generating a sequence of numbers whose properties approximate the properties of sequences of random numbers. The PRNG-generate ...
. There are many possible randomness tests for random permutations, such as some of the
Diehard tests The diehard tests are a battery of statistical tests for measuring the quality of a random number generator. They were developed by George Marsaglia over several years and first published in 1995 on a CD-ROM of random numbers. Test overview ; Bi ...
. A typical example of such a test is to take some
permutation statistic The statistics of random permutations, such as the cycle structure of a random permutation are of fundamental importance in the analysis of algorithms, especially of sorting algorithms, which operate on random permutations. Suppose, for example, t ...
for which the distribution is known and test whether the distribution of this statistic on a set of randomly generated permutations closely approximates the true distribution.


See also

* Ewens's sampling formula — a connection with
population genetics Population genetics is a subfield of genetics that deals with genetic differences within and between populations, and is a part of evolutionary biology. Studies in this branch of biology examine such phenomena as adaptation, speciation, and po ...
* Faro shuffle * Golomb–Dickman constant * Random permutation statistics * Shuffling algorithms — random sort method, iterative exchange method *
Pseudorandom permutation In cryptography, a pseudorandom permutation (PRP) is a function that cannot be distinguished from a random permutation (that is, a permutation selected at random with uniform probability, from the family of all permutations on the function's domai ...


References

{{Reflist


External links


Random permutation
at
MathWorld ''MathWorld'' is an online mathematics reference work, created and largely written by Eric W. Weisstein. It is sponsored by and licensed to Wolfram Research, Inc. and was partially funded by the National Science Foundation's National Science Di ...

Random permutation generation
-- detailed and practical explanation of Knuth shuffle algorithm and its variants for generating ''k''-permutations (permutations of ''k'' elements chosen from a list) and ''k''-subsets (generating a subset of the elements in the list without replacement) with pseudocode Permutations Randomized algorithms