Package com.aventrix.jnanoid.jnanoid
Class NanoIdUtils
java.lang.Object
com.aventrix.jnanoid.jnanoid.NanoIdUtils
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final char[]The default alphabet used by this class.static final SecureRandomThe default random number generator used by this class.static final intThe default size used by this class. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringStatic factory to retrieve a url-friendly, pseudo randomly generated, NanoId String.static StringrandomNanoId(Random random, char[] alphabet, int size) Static factory to retrieve a NanoId String.
-
Field Details
-
DEFAULT_NUMBER_GENERATOR
The default random number generator used by this class. Creates cryptographically strong NanoId Strings. -
DEFAULT_ALPHABET
public static final char[] DEFAULT_ALPHABETThe default alphabet used by this class. Creates url-friendly NanoId Strings using 64 unique symbols. -
DEFAULT_SIZE
public static final int DEFAULT_SIZEThe default size used by this class. Creates NanoId Strings with slightly more unique values than UUID v4.- See Also:
-
-
Method Details
-
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
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.
-