Scholar.randomString( [int len] ) -- generate a random string
This commit is contained in:
parent
c2c0f0f614
commit
0d27815694
1 changed files with 18 additions and 0 deletions
|
@ -21,6 +21,7 @@ var Scholar = new function(){
|
|||
this.getString = getString;
|
||||
this.flattenArguments = flattenArguments;
|
||||
this.join = join;
|
||||
this.randomString = randomString;
|
||||
|
||||
this.Hash = Hash;
|
||||
|
||||
|
@ -177,6 +178,23 @@ var Scholar = new function(){
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a random string of length 'len' (defaults to 8)
|
||||
**/
|
||||
function randomString(len) {
|
||||
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
|
||||
if (!len){
|
||||
len = 8;
|
||||
}
|
||||
var randomstring = '';
|
||||
for (var i=0; i<len; i++) {
|
||||
var rnum = Math.floor(Math.random() * chars.length);
|
||||
randomstring += chars.substring(rnum,rnum+1);
|
||||
}
|
||||
return randomstring;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class for creating hash arrays that behave a bit more sanely
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue