@Test public void testGenerateID() { RandomLogTraceIDGenerator gen = new RandomLogTraceIDGenerator(); String id = gen.generate(); String[] parts = id.split("-"); String lastHostName = parts[0]; String time = parts[1]; String randChars = parts[2]; Assert.assertTrue(randChars.matches("^[A-Za-z\\d]{8}$")); System.out.println(id); }
public String generate() { String id = ""; try { String hostName = getLastHostName(); char[] randomChars = new char[8]; int count = 0; Random random = new Random(); while (count < 8) { int randomAscii = random.nextInt(122); if (randomAscii >= 48 && randomAscii <= 57) { randomChars[count] = (char) ('0' + (randomAscii - 48)); count++; } else if (randomAscii >= 65 && randomAscii <= 90) { randomChars[count] = (char) ('A' + (randomAscii - 65)); count++; } else if (randomAscii >= 97 && randomAscii <= 122) { randomChars[count] = (char) ('a' + (randomAscii - 97)); count++; } } id = formatID(hostName, randomChars); } catch (UnknownHostException e) { System.out.println(e); } return id; }
IDGenerate { public String generate() { String id = ""; try { String hostName = getLastHostName(); char[] randomChars = new char[8]; int count = 0; Random random = new Random(); while (count < 8) { int randomAscii = random.nextInt(122); if (randomAscii >= 48 && randomAscii <= 57) { randomChars[count] = (char) ('0' + (randomAscii - 48)); count++; } else if (randomAscii >= 65 && randomAscii <= 90) { randomChars[count] = (char) ('A' + (randomAscii - 65)); count++; } else if (randomAscii >= 97 && randomAscii <= 122) { randomChars[count] = (char) ('a' + (randomAscii - 97)); count++; } } id = formatID(hostName, randomChars); } catch (UnknownHostException e) { System.out.println(e); } return id; } }
IDGenerate { public String generate() { String id = ""; try { String hostName = getLastHostName(); char[] randomChars = new char[8]; int count = 0; Random random = new Random(); while (count < 8) { int randomAscii = random.nextInt(122); if (randomAscii >= 48 && randomAscii <= 57) { randomChars[count] = (char) ('0' + (randomAscii - 48)); count++; } else if (randomAscii >= 65 && randomAscii <= 90) { randomChars[count] = (char) ('A' + (randomAscii - 65)); count++; } else if (randomAscii >= 97 && randomAscii <= 122) { randomChars[count] = (char) ('a' + (randomAscii - 97)); count++; } } id = formatID(hostName, randomChars); } catch (UnknownHostException e) { System.out.println(e); } return id; }  }
IDGenerate { public String generate() { String id = ""; try { String hostName = getLastHostName(); char[] randomChars = new char[8]; int count = 0; Random random = new Random(); while (count < 8) { int randomAscii = random.nextInt(122); if (randomAscii >= 48 && randomAscii <= 57) { randomChars[count] = (char) ('0' + (randomAscii - 48)); count++; } else if (randomAscii >= 65 && randomAscii <= 90) { randomChars[count] = (char) ('A' + (randomAscii - 65)); count++; } else if (randomAscii >= 97 && randomAscii <= 122) { randomChars[count] = (char) ('a' + (randomAscii - 97)); count++; } } id = formatID(hostName, randomChars); } catch (UnknownHostException e) { System.out.println(e); } return id; }  String generate(); }
IDGenerate { public String generate() { String id = ""; try { String hostName = getLastHostName(); char[] randomChars = new char[8]; int count = 0; Random random = new Random(); while (count < 8) { int randomAscii = random.nextInt(122); if (randomAscii >= 48 && randomAscii <= 57) { randomChars[count] = (char) ('0' + (randomAscii - 48)); count++; } else if (randomAscii >= 65 && randomAscii <= 90) { randomChars[count] = (char) ('A' + (randomAscii - 65)); count++; } else if (randomAscii >= 97 && randomAscii <= 122) { randomChars[count] = (char) ('a' + (randomAscii - 97)); count++; } } id = formatID(hostName, randomChars); } catch (UnknownHostException e) { System.out.println(e); } return id; }  String generate();  }