본문 바로가기

카테고리 없음

Random Key Generator Node Js



This module allows you to generate length-efficient unique IDs, that can be used instead of UUID (v4). The generator uses a limited dictionary space of characters and generates IDs of increasing length to allow for Length-Efficient ids as opposed to UUIDs, that always generate IDs of length 36 or 48 from the getgo.

Random

Given a dictionary size of M and an required ID length <= n, the generator has an output space of:

May 24, 2019  Instead of using the unsafe Math.random, Nano ID uses the crypto module in Node.js and the Web Crypto API in browsers. These modules use unpredictable hardware random generator. Random% alphabet is a popular mistake to make when coding an ID generator. The distribution will not be even; there will be a lower chance for some. Implementation of crypto for the browser. Published 3.12.0. 2 years ago.

This provides very length-efficient IDs even for modest lengths. For example, if you wish to generate IDs of length no greater than 6, then the generator's can output as many as 57,731,386,986 (~57 Billion) unique ids.

Random Key Generator Node Js Tutorial

  • Import the module:

  • Instantiate Id Generator:

  • Generate Counter-based ID:

  • Generate Random ID: