UUIDTest

package com.jake;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.math.RandomUtils;

public class UUIDTest {
	
	public static final String str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";	
	
	private String getString() {
		StringBuffer sb = new StringBuffer();
		String uuid = UUID.randomUUID().toString().replaceAll("-", "");
		for(int i= 0;i<8;i++){
			sb.append(uuid.charAt(RandomUtils.nextInt(30)));
		}		
		sb.append(RandomStringUtils.random(3, str));   
		return sb.toString();
	}

	
	public static void main(String[] args) {
		UUIDTest randomTest = new UUIDTest();		
		System.out.println("测试结果长度" + randomTest.getString());		
		List<String> test = new ArrayList<String>();
		for (int i = 0; i < 100000; i++) {
			test.add(randomTest.getString());
		}
		
		for (int i = 0; i < test.size() - 1; i++) {
			String temp = test.get(i);
			for (int j = i+1; j < test.size(); j++) {
				if (temp.equals(test.get(j))) {
					System.out.println("有相等的了" + temp + test.get(j));
				}
			}
		}
	
	}
	
}

 

你可能感兴趣的:(test)