diff --git a/package.json b/package.json index 1f87311..ae3c419 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "license": "ISC", "dependencies": { "async": "^2.6.2", + "biguint-format": "^1.0.1", "bluebird": "^3.5.3", "bunyan": "^1.8.12", "cheerio": "^1.0.0-rc.3", diff --git a/src/utils/string.util.js b/src/utils/string.util.js index 13f8d3f..edd4219 100644 --- a/src/utils/string.util.js +++ b/src/utils/string.util.js @@ -1,3 +1,5 @@ +import crypto from "crypto"; +import format from 'biguint-format'; export default { /** @@ -35,8 +37,12 @@ export default { } return result; }, + // randomNum(minNum, maxNum) { + // return parseInt(Math.random()*(maxNum-minNum+1)+minNum, 10); + // }, randomNum(minNum, maxNum) { - return parseInt(Math.random()*(maxNum-minNum+1)+minNum, 10); + let x = format(crypto.randomBytes(4), 'dec'); + return parseInt(x / Math.pow(2, 4 * 8) * (maxNum + 1 - minNum) + minNum); }, getContentByReg(str, reg) { const contents = str.match(reg);