choose unique random numbers with specific range

前端 未结 3 1832
南方客
南方客 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:54

    If you have your range in sometype of array, then just use a random over the length of the array.

    For example if you have an int array called range. Then you could use:

    java.utils.Random randomGenarator = new java.utils.Random();
    return range[randomGenarator.nextInt(range.length)];
    

提交回复
热议问题