i am using the below code to create a unique Id which is 8 character (including numeric and alphanumeric characters).
try {
List<String> uuidList = new ArrayList<String>();
int counter = 1;
File file = new File("D://temp//temp1.txt");
file.createNewFile();
Writer writer = new FileWriter(file);
BufferedWriter wr = new BufferedWriter(writer);
while(true) {
int length = bitsArray.length;
Random r = new Random();
StringBuffer uuid = new StringBuffer();
for(int i= 0; i < 8; i++) {
int nextRandomId = r.nextInt(length);
uuid.append(bitsArray[nextRandomId]);
}
String uuidString = uuid.toString();
wr.write(uuidString);
wr.newLine();
if(counter != 1 && uuidList.contains(uuidString)) {
Thread.sleep(1000);
System.err.println(counter);
break;
}
//061e735145fc
System.err.println(uuidString);
uuidList.add(uuidString);
counter++;
}
} catch (Exception e) {
}
i need to know, if i use the above code.. then how many unique ids i can generate. Given
static String[] bitsArray = {"a","b","c","d","e","f","g","h","i",
"j","k","l","m","n","o","p","q","r",
"s","t","u","v","w","x","y","z",
"0","1","2","3","4","5","6","7","8","9"};
Please help..
In essence there is a 368 total strings you can generate.
This theorem is explained by using Discrete Mathematics (using Bit String):
You have 8 character bit string and you need to fill choose 1 out of 36 characters:
Therefore you have
36*36*36*36*36*36*36*36= 368=2,821,109,907,456total id’s.