Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UUID myuuid = UUID.randomUUID();
- long highbits = myuuid.getMostSignificantBits();
- long lowbits = myuuid.getLeastSignificantBits();
- System.out.println("My UUID is: " + highbits + " " + lowbits);
- long hi = id.getMostSignificantBits();
- long lo = id.getLeastSignificantBits();
- byte[] bytes = ByteBuffer.allocate(16).putLong(hi).putLong(lo).array();
- BigInteger big = new BigInteger(bytes);
- String numericUuid = big.toString().replace('-','1'); // just in case
- final int[] pattern = { 8, 4, 4, 4, 12 };
- final int[] versionBit = { 2, 0 }; /* 3rd group, first bit */
- final int version = 4;
- final int[] reservedBit = { 3, 0 }; /* 4rd group, first bit */
- final int reserved = 8; /* 8, 9, A, or B */
- Random rand = new Random();
- String numericUuid = "";
- for (int i = 0; i < pattern.length; i++) {
- for (int j = 0; j < pattern[i]; j++) {
- if (i == versionBit[0] && j == versionBit[1])
- numericUuid += version;
- else if (i == reservedBit[0] && j == reservedBit[1])
- numericUuid += reserved;
- else
- numericUuid += rand.nextInt(10);
- }
- numericUuid += "-";
- }
- UUID uuid = UUID.fromString(numericUuid.substring(0, numericUuid.length() - 1));
- System.out.println(uuid);
- UUID uuid = UUID.randomUUID();
- while (StringUtils.containsAny(uuid.toString(), new char[] { 'a', 'b', 'c', 'd', 'e', 'f' })) {
- uuid = UUID.randomUUID();
- }
- System.out.println(uuid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement