Generate a URL-friendly unique ID using the non-secure, predictable :rand PRNG.
By default the ID has 21 symbols, with a collision probability similar to UUID v4.
Use generate/0 for the all-defaults shortcut, or generate_with/1 with
:size and/or :alphabet for custom IDs. The positional generate/1,2
variants remain available for backward compatibility but are deprecated.
Summary
Functions
Generates a non-secure NanoID using the default size and alphabet.
Generates a non-secure NanoID with the given size.
Generate a non-secure NanoID using a custom size and an individual alphabet.
Generates a non-secure NanoID using a keyword list of options.
Functions
@spec generate() :: binary()
Generates a non-secure NanoID using the default size and alphabet.
Quick-access shortcut, equivalent to generate_with([]).
Example
iex> Nanoid.NonSecure.generate()
"mJUHrGXZBZpNX50x2xkzf"
@spec generate(non_neg_integer()) :: binary()
Generates a non-secure NanoID with the given size.
Deprecated — use generate_with(size: size).
@spec generate(non_neg_integer(), binary() | list()) :: binary()
Generate a non-secure NanoID using a custom size and an individual alphabet.
Deprecated — use generate_with/1 with the :size and :alphabet options instead:
Nanoid.NonSecure.generate_with(size: 12, alphabet: "abcdef123")
Generates a non-secure NanoID using a keyword list of options.
Always pass at least one option — for the no-options shortcut, use generate/0.
Options
:size- the desired ID length in symbols (defaults toNanoid.Configuration.default_size/0):alphabet- the alphabet to draw from, as a binary or charlist (defaults toNanoid.Configuration.default_alphabet/0). Multi-byte graphemes (e.g."äöü"or emoji) are supported.
Examples
iex> Nanoid.NonSecure.generate_with(size: 16)
"IRFa-VaY2b-NU5xX"
iex> Nanoid.NonSecure.generate_with(alphabet: "abcdef123")
"d1dcd2dee333cae1bfdea"
iex> Nanoid.NonSecure.generate_with(size: 12, alphabet: "abcdef123")
"d1dcd2dee333"