2 var assert = require('assert')
4 var base62 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
5 var base36 = 'abcdefghijklmnopqrstuvwxyz0123456789'
6 var base10 = '0123456789'
8 exports = module.exports = create(base62)
9 exports.base62 = exports
10 exports.base36 = create(base36)
11 exports.base10 = create(base10)
13 exports.create = create
15 function create(chars) {
16 assert(typeof chars === 'string', 'the list of characters must be a string!')
17 var length = Buffer.byteLength(chars)
18 return function rndm(len) {
20 assert(typeof len === 'number' && len >= 0, 'the length of the random string must be a number!')
22 for (var i = 0; i < len; i++) salt += chars[Math.floor(length * Math.random())]