faye
Version:
Simple pub/sub messaging for the web
13 lines (10 loc) • 364 B
JavaScript
;
var csprng = require('csprng'),
constants = require('./constants');
module.exports = function(bitlength) {
bitlength = bitlength || constants.ID_LENGTH;
var maxLength = Math.ceil(bitlength * Math.log(2) / Math.log(36));
var string = csprng(bitlength, 36);
while (string.length < maxLength) string = '0' + string;
return string;
};