How to make a random number but it doesn't produce the same number [duplicate]

大憨熊 提交于 2020-01-11 14:35:08

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/14174296/how-to-make-a-random-number-but-it-doesnt-produce-the-same-number

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!