New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pure-rand

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pure-rand - npm Package Compare versions

Comparing version 1.4.2 to 1.5.0

.prettierignore

7

lib/distribution/UniformDistribution.js

@@ -14,3 +14,3 @@ "use strict";

if (deltaV < MAX_ALLOWED) {
return [deltaV % diff + from, nrng];
return [(deltaV % diff) + from, nrng];
}

@@ -25,3 +25,3 @@ }

}
var maxAllowedRandom = diff * Math.floor(1. * maxRandomValue / diff);
var maxAllowedRandom = diff * Math.floor((1 * maxRandomValue) / diff);
while (true) {

@@ -35,3 +35,3 @@ var value = 0;

if (value < maxAllowedRandom) {
var inDiff = value - diff * Math.floor(1. * value / diff);
var inDiff = value - diff * Math.floor((1 * value) / diff);
return [inDiff + from, nrng];

@@ -51,2 +51,1 @@ }

exports.uniformIntDistribution = uniformIntDistribution;
;

@@ -12,3 +12,3 @@ function uniformIntInternal(from, diff, rng) {

if (deltaV < MAX_ALLOWED) {
return [deltaV % diff + from, nrng];
return [(deltaV % diff) + from, nrng];
}

@@ -23,3 +23,3 @@ }

}
var maxAllowedRandom = diff * Math.floor(1. * maxRandomValue / diff);
var maxAllowedRandom = diff * Math.floor((1 * maxRandomValue) / diff);
while (true) {

@@ -33,3 +33,3 @@ var value = 0;

if (value < maxAllowedRandom) {
var inDiff = value - diff * Math.floor(1. * value / diff);
var inDiff = value - diff * Math.floor((1 * value) / diff);
return [inDiff + from, nrng];

@@ -48,3 +48,2 @@ }

}
;
export { uniformIntDistribution };
function toUint32(num) {
return (num | 0) >= 0 ? (num | 0) : (num | 0) + 4294967296;
return (num | 0) >= 0 ? num | 0 : (num | 0) + 4294967296;
}

@@ -38,3 +38,3 @@ function product32bits(a, b) {

for (var idx = 1; idx !== MersenneTwister.N; ++idx) {
var xored = (out[idx - 1] ^ (out[idx - 1] >>> 30));
var xored = out[idx - 1] ^ (out[idx - 1] >>> 30);
out[idx] = (product32bits(MersenneTwister.F, xored) + idx) | 0;

@@ -66,12 +66,12 @@ }

MersenneTwister.R = 31;
MersenneTwister.A = 0x9908B0DF;
MersenneTwister.A = 0x9908b0df;
MersenneTwister.F = 1812433253;
MersenneTwister.U = 11;
MersenneTwister.S = 7;
MersenneTwister.B = 0x9D2C5680;
MersenneTwister.B = 0x9d2c5680;
MersenneTwister.T = 15;
MersenneTwister.C = 0xEFC60000;
MersenneTwister.C = 0xefc60000;
MersenneTwister.L = 18;
MersenneTwister.MASK_LOWER = (Math.pow(2, MersenneTwister.R)) - 1;
MersenneTwister.MASK_UPPER = (Math.pow(2, MersenneTwister.R));
MersenneTwister.MASK_LOWER = Math.pow(2, MersenneTwister.R) - 1;
MersenneTwister.MASK_UPPER = Math.pow(2, MersenneTwister.R);
return MersenneTwister;

@@ -82,2 +82,1 @@ }());

}
;
import { RandomGenerator, generateN, skipN } from './generator/RandomGenerator';
import { congruential, congruential32 } from './generator/LinearCongruential';
import mersenne from './generator/MersenneTwister';
import { xorshift128plus } from './generator/XorShift';
import Distribution from './distribution/Distribution';
import { uniformIntDistribution } from './distribution/UniformDistribution';
export { RandomGenerator, generateN, skipN, congruential, congruential32, mersenne, Distribution, uniformIntDistribution };
export { RandomGenerator, generateN, skipN, congruential, congruential32, mersenne, xorshift128plus, Distribution, uniformIntDistribution };
import { generateN, skipN } from './generator/RandomGenerator';
import { congruential, congruential32 } from './generator/LinearCongruential';
import mersenne from './generator/MersenneTwister';
import { xorshift128plus } from './generator/XorShift';
import { uniformIntDistribution } from './distribution/UniformDistribution';
export { generateN, skipN, congruential, congruential32, mersenne, uniformIntDistribution };
export { generateN, skipN, congruential, congruential32, mersenne, xorshift128plus, uniformIntDistribution };
"use strict";
exports.__esModule = true;
function toUint32(num) {
return (num | 0) >= 0 ? (num | 0) : (num | 0) + 4294967296;
return (num | 0) >= 0 ? num | 0 : (num | 0) + 4294967296;
}

@@ -40,3 +40,3 @@ function product32bits(a, b) {

for (var idx = 1; idx !== MersenneTwister.N; ++idx) {
var xored = (out[idx - 1] ^ (out[idx - 1] >>> 30));
var xored = out[idx - 1] ^ (out[idx - 1] >>> 30);
out[idx] = (product32bits(MersenneTwister.F, xored) + idx) | 0;

@@ -68,12 +68,12 @@ }

MersenneTwister.R = 31;
MersenneTwister.A = 0x9908B0DF;
MersenneTwister.A = 0x9908b0df;
MersenneTwister.F = 1812433253;
MersenneTwister.U = 11;
MersenneTwister.S = 7;
MersenneTwister.B = 0x9D2C5680;
MersenneTwister.B = 0x9d2c5680;
MersenneTwister.T = 15;
MersenneTwister.C = 0xEFC60000;
MersenneTwister.C = 0xefc60000;
MersenneTwister.L = 18;
MersenneTwister.MASK_LOWER = (Math.pow(2, MersenneTwister.R)) - 1;
MersenneTwister.MASK_UPPER = (Math.pow(2, MersenneTwister.R));
MersenneTwister.MASK_LOWER = Math.pow(2, MersenneTwister.R) - 1;
MersenneTwister.MASK_UPPER = Math.pow(2, MersenneTwister.R);
return MersenneTwister;

@@ -85,2 +85,1 @@ }());

exports["default"] = default_1;
;
import { RandomGenerator, generateN, skipN } from './generator/RandomGenerator';
import { congruential, congruential32 } from './generator/LinearCongruential';
import mersenne from './generator/MersenneTwister';
import { xorshift128plus } from './generator/XorShift';
import Distribution from './distribution/Distribution';
import { uniformIntDistribution } from './distribution/UniformDistribution';
export { RandomGenerator, generateN, skipN, congruential, congruential32, mersenne, Distribution, uniformIntDistribution };
export { RandomGenerator, generateN, skipN, congruential, congruential32, mersenne, xorshift128plus, Distribution, uniformIntDistribution };

@@ -11,3 +11,5 @@ "use strict";

exports.mersenne = MersenneTwister_1["default"];
var XorShift_1 = require("./generator/XorShift");
exports.xorshift128plus = XorShift_1.xorshift128plus;
var UniformDistribution_1 = require("./distribution/UniformDistribution");
exports.uniformIntDistribution = UniformDistribution_1.uniformIntDistribution;
{
"name": "pure-rand",
"version": "1.4.2",
"version": "1.5.0",
"description": " Pure random number generator written in TypeScript",

@@ -9,2 +9,4 @@ "main": "lib/pure-rand.js",

"scripts": {
"format:check": "prettier --list-different \"**/*.{js,ts}\"",
"format:fix": "prettier --write \"**/*.{js,ts}\"",
"build": "tsc",

@@ -28,11 +30,12 @@ "build:esm": "tsc --module es2015 --outDir lib/esm --moduleResolution node",

"@types/mocha": "^5.2.5",
"@types/node": "^10.7.1",
"@types/node": "^10.11.7",
"benchmark": "^2.1.4",
"coveralls": "^3.0.2",
"fast-check": "^1.4.0",
"fast-check": "^1.6.2",
"mocha": "^5.2.0",
"nyc": "^12.0.2",
"source-map-support": "^0.5.8",
"nyc": "^13.0.1",
"prettier": "1.14.3",
"source-map-support": "^0.5.9",
"ts-node": "^7.0.1",
"typescript": "^3.0.1"
"typescript": "^3.1.3"
},

@@ -39,0 +42,0 @@ "keywords": [

@@ -8,3 +8,7 @@ // @ts-check

const { genFor } = require('./helpers');
const { testGenerateWithSameDistribution, testGenerateWithSkipDistributionSingle, testGenerateWithSkipDistribution } = require('./tasks');
const {
testGenerateWithSameDistribution,
testGenerateWithSkipDistributionSingle,
testGenerateWithSkipDistribution
} = require('./tasks');
const Benchmark = require('benchmark');

@@ -23,35 +27,42 @@ const prandRef = require('../lib/pure-rand');

const buildBenchmarks = (type, lib) => {
return [
new Benchmark(
`distribution/no@${type}`,
() => {
const g = genFor(lib, PROF_GEN);
testGenerateWithSkipDistribution(lib, g, NUM_TESTS);
}, benchConf),
new Benchmark(
`distribution/re-use@${type}`,
() => {
const g = genFor(lib, PROF_GEN);
testGenerateWithSameDistribution(lib, g, NUM_TESTS);
}, benchConf),
new Benchmark(
`generator/new@${type}`,
() => {
const g = genFor(lib, PROF_GEN);
testGenerateWithSkipDistributionSingle(lib, g);
}, benchConf)
];
return [
new Benchmark(
`distribution/no@${type}`,
() => {
const g = genFor(lib, PROF_GEN);
testGenerateWithSkipDistribution(lib, g, NUM_TESTS);
},
benchConf
),
new Benchmark(
`distribution/re-use@${type}`,
() => {
const g = genFor(lib, PROF_GEN);
testGenerateWithSameDistribution(lib, g, NUM_TESTS);
},
benchConf
),
new Benchmark(
`generator/new@${type}`,
() => {
const g = genFor(lib, PROF_GEN);
testGenerateWithSkipDistributionSingle(lib, g);
},
benchConf
)
];
};
Benchmark.invoke(
[
...buildBenchmarks('Reference', prandRef),
...buildBenchmarks('Test', prandTest),
...buildBenchmarks('Reference', prandRef),
...buildBenchmarks('Test', prandTest),
], {
name: 'run',
queued: true,
onCycle: (event) => console.log(String(event.target)),
}
[
...buildBenchmarks('Reference', prandRef),
...buildBenchmarks('Test', prandTest),
...buildBenchmarks('Reference', prandRef),
...buildBenchmarks('Test', prandTest)
],
{
name: 'run',
queued: true,
onCycle: event => console.log(String(event.target))
}
);

@@ -5,4 +5,4 @@ // @ts-check

exports.genFor = (lib, genName) => {
const seed = 42;
return lib[genName](seed);
const seed = 42;
return lib[genName](seed);
};

@@ -19,4 +19,8 @@ // @ts-check

switch (PROF_TYPE) {
case 'same': testGenerateWithSameDistribution(prand, g, NUM_TESTS); break;
case 'skip': testGenerateWithSkipDistribution(prand, g, NUM_TESTS); break;
case 'same':
testGenerateWithSameDistribution(prand, g, NUM_TESTS);
break;
case 'skip':
testGenerateWithSkipDistribution(prand, g, NUM_TESTS);
break;
}

@@ -5,9 +5,9 @@ // @ts-check

exports.testGenerateWithSkipDistributionSingle = (lib, g) => {
return lib.uniformIntDistribution(0, 0xffffffff, g)[1];
return lib.uniformIntDistribution(0, 0xffffffff, g)[1];
};
exports.testGenerateWithSkipDistribution = (lib, g, NUM_TESTS) => {
for (let idx = 0 ; idx !== NUM_TESTS ; ++idx) {
g = exports.testGenerateWithSkipDistributionSingle(lib, g);
}
return g;
for (let idx = 0; idx !== NUM_TESTS; ++idx) {
g = exports.testGenerateWithSkipDistributionSingle(lib, g);
}
return g;
};

@@ -18,7 +18,7 @@

exports.testGenerateWithSameDistribution = (lib, g, NUM_TESTS) => {
const dist = lib.uniformIntDistribution(0, 0xffffffff);
for (let idx = 0 ; idx !== NUM_TESTS ; ++idx) {
g = dist(g)[1];
}
return g;
const dist = lib.uniformIntDistribution(0, 0xffffffff);
for (let idx = 0; idx !== NUM_TESTS; ++idx) {
g = dist(g)[1];
}
return g;
};

@@ -96,2 +96,3 @@ # pure-rand

The following generators are available:
- `prand.xorshift128plus(seed: number)`: xorshift128+ generator whose values are within the range -0x80000000 to 0x7fffffff
- `prand.mersenne(seed: number)`: Mersenne Twister generator whose values are within the range 0 to 0xffffffff

@@ -98,0 +99,0 @@ - `prand.congruential(seed: number)`: Linear Congruential generator whose values are within the range 0 to 0x7fff

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc