[google面试题]given a deck of cards, how can you shuffle them such that any permutation of cards is equally likely?
Good answer:Go through the elements in order,swapping each element with arandom element in the array that doesnot appear earlier than the element.Thistakes O(n) time.
页:
[1]