How to select random values from a given range

前端 未结 6 615
一整个雨季
一整个雨季 2021-01-06 10:44

I\'m trying to create an android application which will generate random series of values (integer numbers in this case) in a given range (but NOT equal betw

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-06 11:41

    in the edit code:

    int idx = r.nextInt();
    

    needs to change to:

    int idx = r.nextInt(data.length);
    

    because you want to choose a random index from your data.

提交回复
热议问题