Package ru.cwcode.cwutils.text.nanoid
Class NanoID
java.lang.Object
ru.cwcode.cwutils.text.nanoid.NanoID
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char[]The default alphabet used by this class.static final SecureRandomstatic 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(int size) Static factory to retrieve a NanoId String.static StringrandomNanoId(Random random, char[] alphabet, int size) Static factory to retrieve a NanoId String.
-
Field Details
-
DEFAULT_NUMBER_GENERATOR
-
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:
size- The number of symbols in the NanoId String.- 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.
-