add string helpers

This commit is contained in:
Liam 2022-11-13 20:19:47 +00:00
parent 28719eb898
commit 2b9dbd0e83

View File

@ -0,0 +1,16 @@
/**
* Returns a randomly generated string with the specified length
*
* @param {Number} length
* @returns The 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;
}