01: package de.schlund.pfixcore.util;
02:
03: import java.math.BigInteger;
04: import java.util.HashSet;
05: import java.util.Random;
06: import java.util.Set;
07:
08: public class TokenUtils {
09:
10: private final static Random RANDOM = new Random();
11:
12: public static String createRandomToken() {
13: return Long.toString(System.currentTimeMillis(), 36)
14: .toUpperCase()
15: + new BigInteger(64, RANDOM).toString(36).toUpperCase();
16: }
17:
18: public static void main(String[] args) {
19: final Set<String> tokens = new HashSet<String>();
20: for (int i = 0; i < 50; i++) {
21: Thread t = new Thread() {
22: @Override
23: public void run() {
24: for (int j = 0; j < 1000; j++) {
25: String str = createRandomToken();
26: if (tokens.contains(str))
27: System.out
28: .println("Duplicate token found!!!");
29: tokens.add(str);
30: }
31: }
32: };
33: t.start();
34: }
35: System.out.println(createRandomToken());
36: }
37:
38: }
|