You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
477 B
16 lines
477 B
const crypto = require('crypto'); |
|
const Random = require('crypto-random'); |
|
|
|
//returns a random number in range of [1 - max] |
|
function randomNumber(max = 5, min = 1) { |
|
return Random.range(0, max); |
|
} |
|
|
|
//returns a random hex string |
|
function randomString(length = 20) { |
|
const bytesCount = Math.ceil(length / 2); |
|
return crypto.randomBytes(bytesCount).toString('hex').substring(0, length); |
|
} |
|
|
|
module.exports.randomNumber = randomNumber; |
|
module.exports.randomString = randomString;
|
|
|