Skip to content

Instantly share code, notes, and snippets.

@mmalone
Created November 6, 2015 02:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmalone/153e9c1872cd2927ca66 to your computer and use it in GitHub Desktop.
Save mmalone/153e9c1872cd2927ca66 to your computer and use it in GitHub Desktop.
var ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
random_base64 = function random_base64(length) {
var str = "";
for (var i=0; i < length; ++i) {
var rand = Math.floor(Math.random() * ALPHABET.length);
str += ALPHABET.substring(rand, rand+1);
}
return str;
}
@krasilnikow
Copy link

substring быстрее чем обращение по индексу?

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