Class NanoIdUtils

java.lang.Object
com.aventrix.jnanoid.jnanoid.NanoIdUtils

public final class NanoIdUtils extends Object
A class for generating unique String IDs. The implementations of the core logic in this class are based on NanoId, a JavaScript library by Andrey Sitnik released under the MIT license. (https://github.com/ai/nanoid)
Author:
David Klebanoff
  • Field Details

    • DEFAULT_NUMBER_GENERATOR

      public static final SecureRandom DEFAULT_NUMBER_GENERATOR
      The default random number generator used by this class. Creates cryptographically strong NanoId Strings.
    • 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(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.