Socket
Socket
Sign inDemoInstall

big-integer

Package Overview
Dependencies
0
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.6.45 to 1.6.46

11

BigInteger.js

@@ -933,3 +933,3 @@ var bigInt = (function (undefined) {

BigInteger.prototype.isProbablePrime = function (iterations) {
BigInteger.prototype.isProbablePrime = function (iterations, rng) {
var isPrime = isBasicPrime(this);

@@ -940,3 +940,3 @@ if (isPrime !== undefined) return isPrime;

for (var a = [], i = 0; i < t; i++) {
a.push(bigInt.randBetween(2, n.minus(2)));
a.push(bigInt.randBetween(2, n.minus(2), rng));
}

@@ -1173,8 +1173,9 @@ return millerRabinTest(n, a);

}
function randBetween(a, b) {
function randBetween(a, b, rng) {
a = parseValue(a);
b = parseValue(b);
var usedRNG = rng || Math.random;
var low = min(a, b), high = max(a, b);
var range = high.subtract(low).add(1);
if (range.isSmall) return low.add(Math.floor(Math.random() * range));
if (range.isSmall) return low.add(Math.floor(usedRNG() * range));
var digits = toBase(range, BASE).value;

@@ -1184,3 +1185,3 @@ var result = [], restricted = true;

var top = restricted ? digits[i] : BASE;
var digit = truncate(Math.random() * top);
var digit = truncate(usedRNG() * top);
result.push(digit);

@@ -1187,0 +1188,0 @@ if (digit < top) restricted = false;

{
"name": "big-integer",
"version": "1.6.45",
"version": "1.6.46",
"author": "Peter Olson <peter.e.c.olson+npm@gmail.com>",

@@ -5,0 +5,0 @@ "description": "An arbitrary length integer library for Javascript",

@@ -52,3 +52,3 @@ # BigInteger.js [![Build Status][travis-img]][travis-url] [![Coverage Status][coveralls-img]][coveralls-url] [![Monthly Downloads][downloads-img]][downloads-url]

var bigNumber = bigInt(largeNumber);
var maximumByte = bigInt("FF", 16);

@@ -72,3 +72,3 @@ var fiftyFiveGoogol = bigInt("<55>0", googol);

- `bigInt.minusOne`, equivalent to `bigInt(-1)`
The numbers from -999 to 999 are also already prestored and can be accessed using `bigInt[index]`, for example:

@@ -93,3 +93,3 @@

- `bigInt(5).add(7)` => `12`
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Addition)

@@ -135,3 +135,3 @@

- `bigInt(59).divide(5)` => `11`
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Division)

@@ -145,3 +145,3 @@

- `bigInt(-5).divmod(2)` => `{quotient: bigInt(-2), remainder: bigInt(-1) }`
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Division)

@@ -229,6 +229,6 @@

#### `isProbablePrime([iterations])`
#### `isProbablePrime([iterations], [rng])`
Returns `true` if the number is very likely to be prime, `false` otherwise.
Argument is optional and determines the amount of iterations of the test (default: `5`). The more iterations, the lower chance of getting a false positive.
Supplying `iterations` is optional - it determines the number of iterations of the test (default: `5`). The more iterations, the lower chance of getting a false positive.
This uses the [Miller Rabin test](https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test).

@@ -239,4 +239,8 @@

- `bigInt(1729).isProbablePrime()` => `false`
Note that this function is not deterministic, since it relies on random sampling of factors, so the result for some numbers is not always the same.
Note that this function is not deterministic, since it relies on random sampling of factors, so the result for some numbers is not always the same - unless you pass a predictable random number generator as `rng`. The behavior and requirements are the same as with `randBetween`.
- `bigInt(1729).isProbablePrime(1, () => 0.1)` => `false`
- `bigInt(1729).isProbablePrime(1, () => 0.2)` => `true`
If the number is composite then the Miller–Rabin primality test declares the number probably prime with a probability at most `4` to the power `−iterations`.

@@ -290,3 +294,3 @@ If the number is prime, this function always returns `true`.

- `bigInt(3).minus(5)` => `-2`
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Subtraction)

@@ -300,3 +304,3 @@

- `bigInt(-5).mod(2)` => `-1`
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Division)

@@ -361,3 +365,3 @@

- `bigInt(59).over(5)` => `11`
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Division)

@@ -370,3 +374,3 @@

- `bigInt(5).plus(7)` => `12`
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Addition)

@@ -413,3 +417,3 @@

- `bigInt(3).square()` => `9`
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Squaring)

@@ -422,3 +426,3 @@

- `bigInt(3).subtract(5)` => `-2`
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Subtraction)

@@ -431,3 +435,3 @@

- `bigInt(111).times(111)` => `12321`
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#Multiplication)

@@ -491,3 +495,3 @@

- `bigInt(12).xor(-5)` => `-9`
### Static Methods

@@ -514,9 +518,9 @@

- `bigInt.isInstance(14)` => `false`
#### `lcm(a,b)`
Finds the least common multiple of `a` and `b`.
- `bigInt.lcm(21, 6)` => `42`
#### `max(a,b)`

@@ -534,9 +538,13 @@

#### `randBetween(min, max)`
#### `randBetween(min, max, [rng])`
Returns a random number between `min` and `max`.
Returns a random number between `min` and `max`, optionally using `rng` to generate randomness.
- `bigInt.randBetween("-1e100", "1e100")` => (for example) `8494907165436643479673097939554427056789510374838494147955756275846226209006506706784609314471378745`
`rng` should take no arguments and return a `number` between 0 and 1. It defaults to `Math.random`.
- `bigInt.randBetween("-1e100", "1e100", () => 0.5)` => (always) `50000005000000500000050000005000000500000050000005000000500000050000005000000500000050000005000000`
### Override Methods

@@ -578,5 +586,5 @@

- `bigInt(1).toString(0)` => `Error: Cannot convert nonzero numbers to base 0.`
[View benchmarks for this method](http://peterolson.github.io/BigInteger.js/benchmark/#toString)
#### `valueOf()`

@@ -583,0 +591,0 @@

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc