Answers for "random string generator node.js"

23

node random string

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

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

js random string

function randomString(length) {
		var result           = '';
		var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_+=-';
		var charactersLength = characters.length;
		for ( var i = 0; i < length; i++ ) {
		   result += characters.charAt(Math.floor(Math.random() * charactersLength));
		}
		return result;
	 }
randomString(4);
Posted by: Guest on October-27-2020
1

random string generator node js

function makeid(length) {
    var result           = [];
    var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var charactersLength = characters.length;
    for ( var i = 0; i < length; i++ ) {
      result.push(characters.charAt(Math.floor(Math.random() * 
 charactersLength)));
   }
   return result.join('');
}

console.log(makeid(5));
Posted by: Guest on April-19-2021
7

random string js

const string_length = 10
[...Array(string_length)].map(i=>(~~(Math.random()*36)).toString(36)).join('')
Posted by: Guest on September-04-2020
0

randomstring npm

npm install randomstring
Posted by: Guest on August-12-2020
-1

how to generate random strings in js/Node/Javascript

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

2.
let r = (Math.random() + 1).toString(36).substring(7);
console.log("random", r);

3.
function randomString(len) {
  var str = "";                                // String result
  for (var i = 0; i < len; i++) {              // Loop `len` times
    var rand = Math.floor(Math.random() * 62); // random: 0..61
    var charCode = rand += rand > 9 ? (rand < 36 ? 55 : 61) : 48; // Get correct charCode
    str += String.fromCharCode(charCode);      // add Character to str
  }
  return str; // After all loops are done, return the concatenated string
}
console.log(randomString(10));
Posted by: Guest on September-24-2021

Code answers related to "random string generator node.js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language