Class NanoID

java.lang.Object
ru.cwcode.cwutils.text.nanoid.NanoID

public class NanoID extends Object
  • Field Details

    • DEFAULT_NUMBER_GENERATOR

      public static final SecureRandom DEFAULT_NUMBER_GENERATOR
    • DEFAULT_ALPHABET

      public static final char[] DEFAULT_ALPHABET
      The default alphabet used by this class. Creates url-friendly NanoId Strings using 64 unique symbols.
    • DEFAULT_SIZE

      public static final int DEFAULT_SIZE
      The default size used by this class. Creates NanoId Strings with slightly more unique values than UUID v4.
      See Also:
  • Method Details

    • randomNanoId

      public static String randomNanoId()
      Static factory to retrieve a url-friendly, pseudo randomly generated, NanoId String.

      The generated NanoId String will have 21 symbols.

      The NanoId String is generated using a cryptographically strong pseudo random number generator.

      Returns:
      A randomly generated NanoId String.
    • randomNanoId

      public static String randomNanoId(int size)
      Static factory to retrieve a NanoId String.

      The string is generated using the given random number generator.

      Parameters:
      size - The number of symbols in the NanoId String.
      Returns:
      A randomly generated NanoId String.
    • randomNanoId

      public static String randomNanoId(Random random, char[] alphabet, int size)
      Static factory to retrieve a NanoId String.

      The string is generated using the given random number generator.

      Parameters:
      random - The random number generator.
      alphabet - The symbols used in the NanoId String.
      size - The number of symbols in the NanoId String.
      Returns:
      A randomly generated NanoId String.