Generate random numbers except certain values

后端 未结 5 1125
借酒劲吻你
借酒劲吻你 2020-12-01 15:03

I want to generate random numbers, but don\'t want them to be from exclude array. Here is my code.

public int generateRandom(int start, int end,         


        
5条回答
  •  猫巷女王i
    2020-12-01 15:46

    if(!exclude.contains(random))
        return random;
    

    Try this every time it will return the value that is not in exclude.

提交回复
热议问题