Posted on 2008-12-04 15:32
齐纳尔多 阅读(684)
评论(0) 编辑 收藏 所属分类:
java
package com.qpb.ant;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class TestRandom {
public final static int TOTAL = 33;
public final static int NUMBER = 7;
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
StringBuffer sb = new StringBuffer();
Random r = new Random();
for(int i = 0; i < TOTAL; i++) {
list.add(i + 1 + "");
}
for(int j = 0; j < NUMBER; j++) {
int size = list.size();
String s = list.get(r.nextInt(size));
sb.append(s);
if(j != NUMBER -1) {
sb.append(",");
}
list.remove(s);
}
System.out.println(sb.toString());
}
}