Nice function! But one thing I noticed is that this will only work for random alpha-numeric strings up to a certain length. If you want to have something longer, you should call the method recursively. Something like:
const generateRandomString = function (length, randomString="") { randomString += Math.random().toString(20).substr(2, length); if (randomString.length > length) return randomString.slice(0, length); return generateRandomString(length, randomString); };
Yep, looks like it tops out at 12-13 characters for me, demo here: jsfiddle.net/mberwk8a/2/
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice function! But one thing I noticed is that this will only work for random alpha-numeric strings up to a certain length. If you want to have something longer, you should call the method recursively. Something like:
Yep, looks like it tops out at 12-13 characters for me, demo here: jsfiddle.net/mberwk8a/2/