generate random character in javascript 1

generate random character in javascript

var crypto = require("crypto");
var id = crypto.randomBytes(20).toString('hex');

// "bb5dc8842ca31d4603d6aa11448d1654"

Here is what the above code is Doing:
1. We’re requiring the crypto module.
2. We’re creating a variable called crypto and assigning it the value of the crypto module.
3. We’re creating a variable called id and assigning it the value of a random 20-byte hexadecimal number.

Similar Posts