Pick random element from array, but unique

后端 未结 1 1632
深忆病人
深忆病人 2021-01-17 18:07

I have array of countries. I want to pick 5 random countries from my array list, but I want them to be unique. This is what I have so far:

String allCountrie         


        
相关标签:
1条回答
  • 2021-01-17 19:00

    Shuffle the array and then slice the first 5 elements.

    This will guarantee 5 unique random elements.

    0 讨论(0)
提交回复
热议问题