2023-01-05 01:09:51 +03:00
|
|
|
const crypto = require('crypto');
|
|
|
|
const Random = require('crypto-random');
|
|
|
|
|
|
|
|
//returns a random number in range of [1 - max]
|
2023-01-23 07:43:01 +03:00
|
|
|
function randomNumber(max = 5, min = 1) {
|
|
|
|
return Random.range(0, max);
|
2023-01-05 01:09:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//returns a random hex string
|
|
|
|
function randomString(length = 20) {
|
2023-01-23 07:43:01 +03:00
|
|
|
const bytesCount = Math.ceil(length / 2);
|
|
|
|
return crypto.randomBytes(bytesCount).toString('hex').substring(0, length);
|
2023-01-05 01:09:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.randomNumber = randomNumber;
|
|
|
|
module.exports.randomString = randomString;
|