×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Added: May 1, 2014 8:12 PM
Views: 1746
Tags: code js radom
  1. Controller.prototype.getRandomString = function(len, charSet) {
  2.         charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  3.         var randomString = '';
  4.         for (var i = 0; i < len; i++) {
  5.             var randomPoz = Math.floor(Math.random() * charSet.length);
  6.             randomString += charSet.substring(randomPoz, randomPoz + 1);
  7.         }
  8.         return randomString;
  9.     };