Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Random String Generator

node v8.17.0
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