标签:interview
// Randomly generate a int k from 1(inclusive) to n(inclusive). int random(int n); class DeckShuffle() { // Init a deck with 52 cards. private int[] init() // Swap element private void swap(int[] a, int from, int to) int[] next() { int[] deck = init(); for (int i = 0 ; i < deck.length - 1 ; i ++) { int pos = random(52 - i); swap(deck, pos, i); } return deck; } }
标签:interview
原文地址:http://7371901.blog.51cto.com/7361901/1588538