import java.util.Random;
public class Generator extends javax.swing.JFrame {
String[] gamesL = new String[] {"Dota 2", "Garrys mod", "Dungeon Defenders"};
Random rand = new Random();
public Generator() {
initComponents();
}
private void initComponents() {...}
private void generateActionPerformed(java.awt.event.ActionEvent evt) {
display.setText("You shall play " + gamesL[0]);
}
问问题
92 次
2 回答
3
使用Collections.shuffle
(你的数组列表)来获得洗牌的随机数组;您需要导入 java.util.Collections。
于 2013-10-13T14:15:25.550 回答
0
这对(字符串)数组(与集合)进行排序
public void unsortStringArray(String[] a) {
int len = a.length;
for(int sourceIdx = 0; sourceIdx<len; sourceIdx++) {
int destIdx = (int) Math.floor(Math.random() * len);
String sx = a[destIdx];
a[destIdx] = a[sourceIdx];
a[sourceIdx] = sx;
}
}
于 2013-10-13T14:55:06.830 回答