Skip to content

Instantly share code, notes, and snippets.

@cm-kazup0n
Last active November 16, 2018 07:34
Show Gist options
  • Save cm-kazup0n/c754296e70204631a7716463ad2dbe1d to your computer and use it in GitHub Desktop.
Save cm-kazup0n/c754296e70204631a7716463ad2dbe1d to your computer and use it in GitHub Desktop.
import java.util.UUID;
import java.time.Instant;
import java.util.Base64;
import java.nio.ByteBuffer;
import java.security.SecureRandom;
/**
AAABZxtu/zzQb1EQOg==:20
AAABZxtu/z1VAsQOvQ==:20
AAABZxtu/z3ckixveA==:20
AAABZxtu/z0h3qPaxg==:20
AAABZxtu/z1k3W2VLw==:20
AAABZxtu/z163jTH1Q==:20
AAABZxtu/z3i5m6qJA==:20
AAABZxtu/z226JKMSA==:20
AAABZxtu/z3SEQXPmQ==:20
AAABZxtu/z6hkC54bA==:20
*/
public class UUIDGen {
public static void main(String[] args) {
for(int i = 0; i < 10; i++){
final String s = gen();
System.out.println(s + ":" + s.length());
}
}
private static String gen(){
final int LONG_SIZE = 8;
final int RANDOM_BYTE = 7;
final byte[] random = new byte[RANDOM_BYTE];
new SecureRandom().nextBytes(random);
final ByteBuffer buff = ByteBuffer.allocate(LONG_SIZE + RANDOM_BYTE);
buff.putLong(Instant.now().toEpochMilli());
buff.put(random);
final String s = Base64.getEncoder().encodeToString(buff.array());
return s;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment