What is the best way to generate a random permutation of n numbers?
For example, say I have a set of numbers 1, 2 and 3 (n = 3)
Set of all possible permutations: {123, 132, 213, 231, 312, 321}
Now, how do I generate:
- one of the elements of the above sets (randomly chosen)
- a whole permutation set as shown above
In other words, if I have an array of n elements, how do I shuffle them randomly? Please assist. Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…