问题
Does java have an inbuilt method to permute or randomly shuffle an Array of numbers or characters? Something like Random Shuffle STL in c++??
回答1:
You can use Collections#shuffle
List<Integer> intList = new ArrayList<Integer>();
Collections.shuffle(intList);
If you have an array of numbers, you can use: -
Collections.shuffle(Arrays.asList(yourArray));
来源:https://stackoverflow.com/questions/12943118/inbuilt-permutation-generator