在4名玩家中随机分配52张牌

pis*_*ise 0 java collections

我想在4名玩家中随机分配52张牌.我虽然我会将每张卡放入HashMap,因为hashmap是无序的和未排序的,然后遍历它并将第1张13张牌分配给玩家1,最后13张牌分配给玩家4.但是当我遍历hashmap时,值总是相同的,我希望每次迭代的值都应该是不同的.下面是使用6号和输出相同的例子.

    public static void main(String[] args) {

    Map<String,String> map = new HashMap<String,String>();
    map.put("1", "one");
    map.put("2", "two");
    map.put("3", "three");
    map.put("4", "four");
    map.put("5", "five");
    map.put("6", "six");

    for(Iterator<Entry<String, String>> iterator =  map.entrySet().iterator(); iterator.hasNext();){
        Entry<String,String> entry = iterator.next();
        System.out.print(entry.getKey()+" "+ entry.getValue() +"\n");
    }

}


Output
3 three
2 two
1 one
6 six
5 five
4 four
Run Code Online (Sandbox Code Playgroud)

N次运行代码但输出在我的机器中始终相同.我希望每次运行都有不同的输出.请指教.

ale*_*s_t 6

不要使用哈希映射,只使用普通列表和Collections.shuffle().

(哈希映射中元素的顺序由其散列函数给出,它不是随机的.)