慕仔1140816
2016-04-27 17:33:35浏览 4420
public void testSort3() {
List<String> stringList = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
StringBuilder tempString = new StringBuilder();
Random random = new Random();
Character[] ku = { '0', 'A', 'a' };
do {
int k = (int) (Math.random() * 10);
// System.out.println(k);
for (int j = 0; j <= k; j++) {
int t = random.nextInt(3);
if (t == 0) {
tempString.append((char) (ku[t].charValue() + random
.nextInt(10)));
} else {
tempString.append((char) (ku[t].charValue() + random
.nextInt(26)));
}
}
} while (stringList.contains(tempString.toString()));
stringList.add(tempString.toString());
}
System.out.println("-------------排序前-------------");
for (String st : stringList) {
System.out.println("元素:" + st);
}
Collections.sort(stringList);
System.out.println("-------------排序后-------------");
for (String st : stringList) {
System.out.println("元素:" + st);
}
}
热门评论
这个取到每个字符的概率不等啊..
int t = random.nextInt(3);
if (t == 0) {
tempString.append((char) (ku[t].charValue() + random .nextInt(10)));
}
else {
tempString.append((char) (ku[t].charValue() + random .nextInt(26)));
}
这里真好!佩服!
这个取到每个字符的概率不等啊..