Comparing version 3.1.0 to 4.0.0
@@ -8,3 +8,3 @@ // Shared Jest configuration | ||
'ts-jest': { | ||
tsConfig: 'tsconfig.json', | ||
tsconfig: 'tsconfig.json', | ||
}, | ||
@@ -11,0 +11,0 @@ }, |
"use strict"; | ||
exports.__esModule = true; | ||
exports.uniformIntDistribution = void 0; | ||
function uniformIntInternal(from, diff, rng) { | ||
var MinRng = rng.min(); | ||
var NumValues = rng.max() - rng.min() + 1; | ||
if (diff <= NumValues) { | ||
var nrng_1 = rng; | ||
var MaxAllowed = NumValues - (NumValues % diff); | ||
while (true) { | ||
var out = nrng_1.next(); | ||
var deltaV = out[0] - MinRng; | ||
nrng_1 = out[1]; | ||
if (deltaV < MaxAllowed) { | ||
return [(deltaV % diff) + from, nrng_1]; | ||
} | ||
} | ||
var UniformIntDistributionInternal_1 = require("./internals/UniformIntDistributionInternal"); | ||
var ArrayInt_1 = require("./internals/ArrayInt"); | ||
var UniformArrayIntDistributionInternal_1 = require("./internals/UniformArrayIntDistributionInternal"); | ||
var sharedA = { sign: 1, data: [0, 0] }; | ||
var sharedB = { sign: 1, data: [0, 0] }; | ||
var sharedC = { sign: 1, data: [0, 0] }; | ||
var sharedData = [0, 0]; | ||
function uniformLargeIntInternal(from, to, rangeSize, rng) { | ||
var rangeSizeArrayIntValue = rangeSize <= Number.MAX_SAFE_INTEGER | ||
? ArrayInt_1.fromNumberToArrayInt64(sharedC, rangeSize) | ||
: ArrayInt_1.substractArrayInt64(sharedC, ArrayInt_1.fromNumberToArrayInt64(sharedA, to), ArrayInt_1.fromNumberToArrayInt64(sharedB, from)); | ||
if (rangeSizeArrayIntValue.data[1] === 0xffffffff) { | ||
rangeSizeArrayIntValue.data[0] += 1; | ||
rangeSizeArrayIntValue.data[1] = 0; | ||
} | ||
var FinalNumValues = NumValues * NumValues; | ||
var NumIterations = 2; | ||
while (FinalNumValues < diff) { | ||
FinalNumValues *= NumValues; | ||
++NumIterations; | ||
else { | ||
rangeSizeArrayIntValue.data[1] += 1; | ||
} | ||
var MaxAcceptedRandom = diff * Math.floor((1 * FinalNumValues) / diff); | ||
var nrng = rng; | ||
while (true) { | ||
var value = 0; | ||
for (var num = 0; num !== NumIterations; ++num) { | ||
var out = nrng.next(); | ||
value = NumValues * value + (out[0] - MinRng); | ||
nrng = out[1]; | ||
} | ||
if (value < MaxAcceptedRandom) { | ||
var inDiff = value - diff * Math.floor((1 * value) / diff); | ||
return [inDiff + from, nrng]; | ||
} | ||
var g = UniformArrayIntDistributionInternal_1.uniformArrayIntDistributionInternal(sharedData, rangeSizeArrayIntValue.data, rng); | ||
return [sharedData[0] * 0x100000000 + sharedData[1] + from, g[1]]; | ||
} | ||
function uniformIntInternal(from, to, rng) { | ||
var rangeSize = to - from; | ||
if (rangeSize <= 0xffffffff) { | ||
var g = UniformIntDistributionInternal_1.uniformIntDistributionInternal(rangeSize + 1, rng); | ||
g[0] += from; | ||
return g; | ||
} | ||
return uniformLargeIntInternal(from, to, rangeSize, rng); | ||
} | ||
function uniformIntDistribution(from, to, rng) { | ||
var diff = to - from + 1; | ||
if (rng != null) { | ||
return uniformIntInternal(from, diff, rng); | ||
return uniformIntInternal(from, to, rng); | ||
} | ||
return function (rng) { | ||
return uniformIntInternal(from, diff, rng); | ||
return uniformIntInternal(from, to, rng); | ||
}; | ||
} | ||
exports.uniformIntDistribution = uniformIntDistribution; |
@@ -1,46 +0,39 @@ | ||
function uniformIntInternal(from, diff, rng) { | ||
var MinRng = rng.min(); | ||
var NumValues = rng.max() - rng.min() + 1; | ||
if (diff <= NumValues) { | ||
var nrng_1 = rng; | ||
var MaxAllowed = NumValues - (NumValues % diff); | ||
while (true) { | ||
var out = nrng_1.next(); | ||
var deltaV = out[0] - MinRng; | ||
nrng_1 = out[1]; | ||
if (deltaV < MaxAllowed) { | ||
return [(deltaV % diff) + from, nrng_1]; | ||
} | ||
} | ||
import { uniformIntDistributionInternal } from './internals/UniformIntDistributionInternal.js'; | ||
import { fromNumberToArrayInt64, substractArrayInt64 } from './internals/ArrayInt.js'; | ||
import { uniformArrayIntDistributionInternal } from './internals/UniformArrayIntDistributionInternal.js'; | ||
var sharedA = { sign: 1, data: [0, 0] }; | ||
var sharedB = { sign: 1, data: [0, 0] }; | ||
var sharedC = { sign: 1, data: [0, 0] }; | ||
var sharedData = [0, 0]; | ||
function uniformLargeIntInternal(from, to, rangeSize, rng) { | ||
var rangeSizeArrayIntValue = rangeSize <= Number.MAX_SAFE_INTEGER | ||
? fromNumberToArrayInt64(sharedC, rangeSize) | ||
: substractArrayInt64(sharedC, fromNumberToArrayInt64(sharedA, to), fromNumberToArrayInt64(sharedB, from)); | ||
if (rangeSizeArrayIntValue.data[1] === 0xffffffff) { | ||
rangeSizeArrayIntValue.data[0] += 1; | ||
rangeSizeArrayIntValue.data[1] = 0; | ||
} | ||
var FinalNumValues = NumValues * NumValues; | ||
var NumIterations = 2; | ||
while (FinalNumValues < diff) { | ||
FinalNumValues *= NumValues; | ||
++NumIterations; | ||
else { | ||
rangeSizeArrayIntValue.data[1] += 1; | ||
} | ||
var MaxAcceptedRandom = diff * Math.floor((1 * FinalNumValues) / diff); | ||
var nrng = rng; | ||
while (true) { | ||
var value = 0; | ||
for (var num = 0; num !== NumIterations; ++num) { | ||
var out = nrng.next(); | ||
value = NumValues * value + (out[0] - MinRng); | ||
nrng = out[1]; | ||
} | ||
if (value < MaxAcceptedRandom) { | ||
var inDiff = value - diff * Math.floor((1 * value) / diff); | ||
return [inDiff + from, nrng]; | ||
} | ||
var g = uniformArrayIntDistributionInternal(sharedData, rangeSizeArrayIntValue.data, rng); | ||
return [sharedData[0] * 0x100000000 + sharedData[1] + from, g[1]]; | ||
} | ||
function uniformIntInternal(from, to, rng) { | ||
var rangeSize = to - from; | ||
if (rangeSize <= 0xffffffff) { | ||
var g = uniformIntDistributionInternal(rangeSize + 1, rng); | ||
g[0] += from; | ||
return g; | ||
} | ||
return uniformLargeIntInternal(from, to, rangeSize, rng); | ||
} | ||
function uniformIntDistribution(from, to, rng) { | ||
var diff = to - from + 1; | ||
if (rng != null) { | ||
return uniformIntInternal(from, diff, rng); | ||
return uniformIntInternal(from, to, rng); | ||
} | ||
return function (rng) { | ||
return uniformIntInternal(from, diff, rng); | ||
return uniformIntInternal(from, to, rng); | ||
}; | ||
} | ||
export { uniformIntDistribution }; |
@@ -9,3 +9,3 @@ import { generateN, skipN } from './generator/RandomGenerator.js'; | ||
var __type = 'module'; | ||
var __version = '3.1.0'; | ||
var __version = '4.0.0'; | ||
export { __type, __version, generateN, skipN, congruential, congruential32, mersenne, xorshift128plus, xoroshiro128plus, uniformBigIntDistribution, uniformIntDistribution, }; |
@@ -22,3 +22,3 @@ "use strict"; | ||
exports.__type = __type; | ||
var __version = '3.1.0'; | ||
var __version = '4.0.0'; | ||
exports.__version = __version; |
@@ -10,3 +10,3 @@ "use strict"; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
@@ -13,0 +13,0 @@ exports.__esModule = true; |
{ | ||
"name": "pure-rand", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": " Pure random number generator written in TypeScript", | ||
@@ -44,2 +44,4 @@ "type": "commonjs", | ||
"benchmark": "^2.1.4", | ||
"chalk": "^4.1.0", | ||
"console-table-printer": "2.5.0", | ||
"coveralls": "^3.0.9", | ||
@@ -49,8 +51,10 @@ "fast-check": "^2.0.0", | ||
"jest": "^26.1.0", | ||
"prettier": "2.0.5", | ||
"microtime": "^3.0.0", | ||
"prettier": "2.1.2", | ||
"replace-in-file": "^6.1.0", | ||
"source-map-support": "^0.5.16", | ||
"ts-jest": "^26.1.2", | ||
"ts-node": "^8.6.2", | ||
"typescript": "^3.7.5" | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.0.2", | ||
"yargs": "^16.0.3" | ||
}, | ||
@@ -57,0 +61,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
71516
57
1581
17
1