www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 0d278156941829dc289708bd4bbe291daaa0dd45
parent c2c0f0f614adef7e0dfced835b1eb88ac9a2940d
Author: Dan Stillman <dstillman@zotero.org>
Date:   Thu,  1 Jun 2006 19:46:57 +0000

Scholar.randomString( [int len] ) -- generate a random string


Diffstat:
Mchrome/chromeFiles/content/scholar/xpcom/scholar.js | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/xpcom/scholar.js b/chrome/chromeFiles/content/scholar/xpcom/scholar.js @@ -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 *