Random String Generator

node v8.11.1
version: 4.3.2
endpointsharetweet
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'; function setCharacters(charactersToUse){ characters = charactersToUse; }
function randomString(length){ var string = '' for (var i = 0; i < length; i++){ string += characters.charAt(Math.floor(Math.random() * characters.length)); } return string; }
randomString(10)
randomString(100);
randomString(1000);
randomString(10000);
randomString(1000000)
function twoRandoms(length){ return nRandoms(2, length); }
function nRandoms(n, length) { var outputArray = []; for (var i = 0; i < n; i++){ outputArray.push(randomString(length)); } return outputArray; }
module.exports = { randomString, twoRandoms, nRandoms, setCharacters };
Loading…

no comments

    sign in to comment