choose unique random numbers with specific range

前端 未结 3 1798
南方客
南方客 2021-01-27 10:04

my problem is I want my program to make four unique random choices in range of numbers between 0 to 3 I tried to do it in random class but I could not, , if you could help by co

3条回答
  •  深忆病人
    2021-01-27 10:52

    You could fill an (if you don't need too many numbers) ArrayList with numbers ranging from 0 - 3. Then you get a random index using Random.nextInt(list.size()), get the number from the list and removeAt the entry at your index.

提交回复
热议问题