1 line
872 B
JSON
1 line
872 B
JSON
{"ast":null,"code":"'use strict';\n/* global crypto:true */\n\nvar crypto = require('crypto'); // This string has length 32, a power of 2, so the modulus doesn't introduce a\n// bias.\n\n\nvar _randomStringChars = 'abcdefghijklmnopqrstuvwxyz012345';\nmodule.exports = {\n string: function string(length) {\n var max = _randomStringChars.length;\n var bytes = crypto.randomBytes(length);\n var ret = [];\n\n for (var i = 0; i < length; i++) {\n ret.push(_randomStringChars.substr(bytes[i] % max, 1));\n }\n\n return ret.join('');\n },\n number: function number(max) {\n return Math.floor(Math.random() * max);\n },\n numberString: function numberString(max) {\n var t = ('' + (max - 1)).length;\n var p = new Array(t + 1).join('0');\n return (p + this.number(max)).slice(-t);\n }\n};","map":null,"metadata":{},"sourceType":"script"} |