View Source Nanoid.Secure (Nanoid v2.1.0)
Generate a secure URL-friendly unique ID. This method uses the secure and non predictable random generator. By default, the ID will have 21 symbols with a collision probability similar to UUID v4.
Summary
Functions
Generates a secure NanoID using the default alphabet.
Generates a secure NanoID using a custom size and an individual alphabet.
Functions
@spec generate(non_neg_integer()) :: binary()
Generates a secure NanoID using the default alphabet.
Example
Generate a NanoID with the default size of 21 characters.
iex> Nanoid.Secure.generate()
"mJUHrGXZBZpNX50x2xkzf"
Generate a secure NanoID with a custom size of 64 characters.
iex> Nanoid.Secure.generate(64)
"wk9fsUrhK9k-MxY0hLazRKpcSlic8XYDFusks7Jb8FwCVnoQaKFSPsmmLHzP7qCX"
@spec generate(non_neg_integer(), binary()) :: binary()
Generates a secure NanoID using a custom size and an individual alphabet.
Example
Generate a secure NanoID with the default size of 21 characters and an individual alphabet.
iex> Nanoid.Secure.generate(21, "abcdef123")
"d1dcd2dee333cae1bfdea"
Generate a secure NanoID with custom size of 64 characters and an individual alphabet.
iex> Nanoid.Secure.generate(64, "abcdef123")
"aabbaca3c11accca213babed2bcd1213efb3e3fa1ad23ecbf11c2ffc123f3bbe"