@typespec/ts-http-runtime
Version:
Isomorphic client library for making HTTP requests in node.js and browser.
24 lines • 1.06 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRandomIntegerInclusive = getRandomIntegerInclusive;
/**
* Returns a random integer value between a lower and upper bound,
* inclusive of both bounds.
* Note that this uses Math.random and isn't secure. If you need to use
* this for any kind of security purpose, find a better source of random.
* @param min - The smallest integer value allowed.
* @param max - The largest integer value allowed.
*/
function getRandomIntegerInclusive(min, max) {
// Make sure inputs are integers.
min = Math.ceil(min);
max = Math.floor(max);
// Pick a random offset from zero to the size of the range.
// Since Math.random() can never return 1, we have to make the range one larger
// in order to be inclusive of the maximum value after we take the floor.
const offset = Math.floor(Math.random() * (max - min + 1));
return offset + min;
}
//# sourceMappingURL=random.js.map