dimanche 16 avril 2023

How to generate a unique 8 digit number using crypto in node js?

I want to generate a unique number everytime. I have used crypto module for that.

const alphanu = crypto.randomBytes(16).toString('hex')

This will generate alphanumeric string of length 32. I want to generate a number of length 8.

I tried randomInt as well.

const num = crypto.randomInt(10000000,99999999)

Will it always generate a unique number?

How do I achieve what I want?




Aucun commentaire:

Enregistrer un commentaire