Answers for "javascript unique string"

23

javascript generate random string

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

// "bb5dc8842ca31d4603d6aa11448d1654"
Posted by: Guest on July-16-2020
10

javascript get random string

function getRandomString(length) {
    var randomChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var result = '';
    for ( var i = 0; i < length; i++ ) {
        result += randomChars.charAt(Math.floor(Math.random() * randomChars.length));
    }
    return result;
}

//usage: getRandomString(20); // pass desired length of random string
Posted by: Guest on July-23-2019
0

unique string id js

const uid = () => {
  return Date.now().toString(36) + Math.random().toString(36).substr(2);
};

// Usage. Example, id = khhry2hb7uip12rj2iu
const id = uid();
Posted by: Guest on August-14-2021

Code answers related to "javascript unique string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language