how to create an array of non-repeated rand numbers

后端 未结 4 971
时光取名叫无心
时光取名叫无心 2021-01-23 02:57

I would like to create a array having 21 values between 0 to 20.I would like them to be in random and at the same time non-repeated.

I know how to create a random number

4条回答
  •  滥情空心
    2021-01-23 03:09

    You can use a Set to add rands until the size is 20, then dump to an array.

    If you need performance, use Guava's HashSet or Trove's TIntSet.

提交回复
热议问题