How to make a random number but it doesn't pro

2019-03-06 19:48发布

Possible Duplicate:
Random permutation of integers using a random number generator

For example I need to make a random number from 1 to 30. But it doesn't produce the same random number. The number produced has to be different one to another.

Is that possible?

Thanks

标签: java random
1条回答
你好瞎i
2楼-- · 2019-03-06 20:10

Create a List<Integer> containing 1-30, shuffle it using Collections.shuffle(), then iterate through the list. Of course, at the end of the list, it's impossible to have a new number that hasn't been generated yet.

查看更多
登录 后发表回答