This class Generate A unique string. You can concatenate Timestamp to this Unique String and use it as Unique ID
Generate A Random String Id
package test;
/*
* @author NAPSTAR
*/
import java.util.Random;
public class XUIDGenerator {
private static final int NUM_CHARS = 10;
private static String chars = "abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
private static Random r = new Random();
public static String getUniqueID() {
char[] buf = new char[NUM_CHARS];
for (int i = 0; i < buf.length; i++) {
buf[i] = chars.charAt(r.nextInt(chars.length()));
}
return new String(buf);
}
public static void main(String[] args) {
System.out.println(XUIDGenerator.getUniqueID());
}
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.