Skip to content

Instantly share code, notes, and snippets.

@agustinhaller
Created August 8, 2013 03:06
Show Gist options
  • Save agustinhaller/6181104 to your computer and use it in GitHub Desktop.
Save agustinhaller/6181104 to your computer and use it in GitHub Desktop.
makeId function
function makeid(length)
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for(var i=0; i < length; i++)
{
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
@alii
Copy link

alii commented Jan 4, 2020

ES6 Version

const makeid = length => {
    let text = "";
    const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    for (let i = 0; i < length; i++) {
        text += possible.charAt(Math.floor(Math.random() * possible.length));
    }

    return text;
}

@Yooooomi
Copy link

Yooooomi commented Jun 3, 2021

ES6 Eslint friendly version

const makeid = length => {
  let text = '';
  const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

  for (let i = 0; i < length; i += 1) {
    text += possible.charAt(Math.floor(Math.random() * possible.length));
  }
  return text;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment