Package io.mats3.util
Class RandomString
java.lang.Object
io.mats3.util.RandomString
If you need a random string for a part of the traceId (Read NOTE about traceIds!), use this class instead of
UUID
, because UUID has low entropy density with only 4 bits per character, and dashes.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
static String
According to the internet, there are ~7.5e18 grains of sand on all the beaches on earth.static String
randomString
(int length)
-
Constructor Details
-
RandomString
public RandomString()
-
-
Method Details
-
randomCorrelationId
According to the internet, there are ~7.5e18 grains of sand on all the beaches on earth. There are 62 points in the alphabet used to create these random strings. 62^20 is 7.0e35. There is slightly more room in a random UUID, but I felt this was adequate.- Returns:
- a 20-char length string, which should be plenty enough uniqueness for pretty much anything - you'll have to make extremely many such strings to get a collision.
-
partTraceId
- Returns:
- a 6-char length string, which should be enough to make an already-very-unique TraceId become unique enough to be pretty sure that you will not ever have problems uniquely identifying log lines for a call flow.
-
randomString
- Parameters:
length
- the desired length of the returned random string.- Returns:
- a random string of the specified length.
-