求大神解,java产生不同的随机数
我写了一段代码,感觉有点慢,有没有更高效的方法? 求大神来,,,程序代码:
public static void main(String[] args) { int suit[] = new int[16]; boolean sw[] = new boolean[16]; int key = 0; for (int i = 0; i < suit.length; i++) { while (true) { key = (int) (Math.random() * 16); if (sw[key] == false) { break; } } suit[i] = key; sw[key] = true; } for (int i = 0; i < suit.length; i++) { System.out.println(suit[i] + " "); } }