参考下
public class ArrayList {
public static void main(String[] args) {
int[] x ={1,2,3,4,5};
int t =(int)( Math.random() * x.length + 1);
System.out.println(t);
}
}
final int offset = 5;
long[] flag = new long[(a.length >> offset) + 1];
int printedCount = 0;
Random rand = new Random();
long time = System.currentTimeMillis();
for (int i = 0; i < a.length; i++) {
int index;
int flagIndex;
int flagValue;
do {
index = rand.nextInt(a.length);
flagIndex = index >> offset;
flagValue = 1 << (index - (flagIndex << offset));
} while ((flag[flagIndex] & flagValue) != 0);
System.out.println(a[index]);
printedCount++;
flag[flagIndex] |= flagValue;
}
int[] b = new int[a.length];
System.arraycopy(a, 0, b, 0, a.length);
Random rand = new Random();
for (int i = b.length - 1; i > 1; i--) {
int index = rand.nextInt(i);
int t = b[i];
b[i] = b[index];
b[index] = t;
}
for (int i = 0; i < b.length; i++) {
System.out.println(b[i]);
}
public class RandomPrint {
private static Random rand = new Random();
public static final int[] x = {1,2,3,4,5};
public static void main(String[] args) {
boolean[] picked = new boolean[x.length];
for(int i = 0; i < x.length; i++) {
int t;
do
t = rand.nextInt(x.length);
while(picked[t]);
System.out.println(x[t]);
picked[t] = true;
}
List list = new ArrayList();
for (int i=0; i<52; i++)
list.add(new Integer(i+1));
Random random = new Random();
while (list.size() > 0) {
int rand = random.nextInt(list.size());
rand = (Integer)list.remove(rand);
// 这个就是你要的了
System.out.println(rand);
}