项目作者: echenim

项目描述 :
The Fisher–Yates shuffle is an algorithm for generating a random permutation of a finite sequence—in plain terms, the algorithm shuffles the sequence. The algorithm effectively puts all the elements into a hat; it continually determines the next element by randomly drawing an element from the hat until no elements remain. The algorithm produces an unbiased permutation: every permutation is equally likely. The modern version of the algorithm is efficient: it takes time proportional to the number of items being shuffled and shuffles them in place. The Fisher–Yates shuffle is named after Ronald Fisher and Frank Yates, who first described it, and is also known as the Knuth shuffle after Donald Knuth. A variant of the Fisher–Yates shuffle, known as Sattolo's algorithm, may be used to generate random cyclic permutations of length n instead of random permutations.
高级语言: C#
项目地址: git://github.com/echenim/FisherYatesShuffle.git
创建时间: 2018-11-17T23:53:04Z
项目社区:https://github.com/echenim/FisherYatesShuffle

开源协议:MIT License

下载


Fisher–Yates shuffle-algorithms

The Fisher–Yates shuffle is an algorithm for generating a random permutation of a finite sequence—in plain terms,

the algorithm shuffles the sequence. The algorithm effectively puts all the elements into a hat; it continually
determines the next element by randomly drawing an element from the hat until no elements remain. The algorithm
produces an unbiased permutation: every permutation is equally likely. The modern version of the algorithm is efficient:
it takes time proportional to the number of items being shuffled and shuffles them in place.

To initialize an array a of n elements to a randomly shuffled copy of source, both 0-based:
for i from 0 to n − 1 do
j ← random integer such that 0 ≤ j ≤ i
if j ≠ i
a[i] ← a[j]
a[j] ← source[i]