Package io.mats3.util

Class RandomString


public class RandomString extends Object
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 Details

    • RandomString

      public RandomString()
  • Method Details

    • randomCorrelationId

      public static String 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.
      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

      public static String partTraceId()
      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

      public static String randomString(int length)
      length - the desired length of the returned random string.
      a random string of the specified length.