-1

I'm using nanoid to generate a unique string ID. I have some questions.

1- When I limit size is the outcome unique?

const nanoid = nanoid(6)

2- I do not want some letters such as (- and _ ) in the result. How can I do that and dose the outcome is unique?

3- I know that I can use customAlphabet to generate keys. dose the result of customAlphabet unique?

import { customAlphabet } from 'nanoid'
const nanoid = customAlphabet('1234567890abcdef', 10)

thanks in advance

AR Second
  • 582
  • 1
  • 6
  • 25

1 Answers1

2

I don't think that nanoid guarantees uniqueness of the IDs it creates. Like UUID, it's probabilistic, based on random number generation. The chance of a collision depends on the size of the alphabet and the length of the ID string - that's why they provide an ID collision probability calculator.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710