android: generate random number without repetition

后端 未结 4 2019
隐瞒了意图╮
隐瞒了意图╮ 2021-01-07 00:03

can anybody help me in making a method to generate random number without repetition in Android? The maximum number is: prjcts.size(); it\'s my JSON Array. And t

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-07 00:21

    I mentioned in your other question how to do this..

    List list = new ArrayList();
    int jsonMax = prjcts.size();
    for(int i = 1; i<=jsonMax; i++)
        list.add(i);
    
    Collections.shuffle(list);
    
    for(int i=0; i

提交回复
热议问题