UNPKG

mute-structs

Version:

NodeJS module providing an implementation of the LogootSplit CRDT algorithm

48 lines (44 loc) 1.77 kB
"use strict"; /* This file is part of Mute-structs. Copyright (C) 2017 Matthieu Nicolas, Victorien Elvinger This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.INT32_BOTTOM = -0x7fffffff - 1; exports.INT32_TOP = 0x7fffffff; /** * @param n * @return Is `n' an int32? */ function isInt32(n) { return typeof n === "number" && Number.isSafeInteger(n) && exports.INT32_BOTTOM <= n && n <= exports.INT32_TOP; } exports.isInt32 = isInt32; /** * @param l lower bound * @param u upper bound * @return random integer 32 in [l, u[ */ function randomInt32(l, u) { console.assert(isInt32(l), "l must be an int32"); console.assert(isInt32(u), "u must be an int32"); console.assert(l < u, "u is greater than l"); var randomFloat = (Math.random() * (u - l)) + l; // Generate a random float number in [b1, b2[ var result = Math.floor(randomFloat); console.assert(isInt32(result) && l <= result && result < u, "result is an integer 32 in [l, u["); return result; } exports.randomInt32 = randomInt32; //# sourceMappingURL=int32.js.map