我会直截了当地提出你的问题:
Random r = new Random(); // Keep this stored as a field
List<Character> l = ...; // initialize this somewhere
char c = l.get(r.nextInt(l.size()));
Run Code Online (Sandbox Code Playgroud)
根据几个因素(字母是连续的,您是否动态调整列表大小),您可以使用数组,或者可能不需要集合.请参阅Random类.
例:
Random r = new Random(); // Keep this stored as a field
List<Character> l = Arrays.asList('A', 'F', 'O', 'W', 'M', 'I', 'C', 'E');
char c = l.get(r.nextInt(l.size()));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4578 次 |
| 最近记录: |