From 5bb3fe48676dad6f8ee43174732fb29f32ea999d Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Fri, 6 Mar 2026 22:47:50 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Bump=20pure-rand=20to=20v8?= =?UTF-8?q?=20(#6679)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Bump our dependency to head for the last generation of this dependency. ## Checklist — _Don't delete this checklist and make sure you do the following before opening the PR_ - [x] I have a full understanding of every line in this PR — whether the code was hand-written, AI-generated, copied from external sources or produced by any other tool - [x] I flagged the impact of my change (minor / patch / major) either by running `pnpm run bump` or by following the instructions from the changeset bot - [x] I kept this PR focused on a single concern and did not bundle unrelated changes - [x] I followed the [gitmoji](https://gitmoji.dev/) specification for the name of the PR, including the package scope (e.g. `🐛(vitest) Something...`) when the change targets a package other than `fast-check` - [x] I added relevant tests and they would have failed without my PR (when applicable) --- .changeset/old-cobras-teach.md | 5 ++ .../mazeGenerator/src/mazeGenerator.ts | 2 +- examples/package.json | 2 +- packages/fast-check/README.md | 19 +++--- packages/fast-check/package.json | 6 +- .../fast-check/src/check/runner/Tosser.ts | 8 +-- .../check/runner/configuration/Parameters.ts | 2 +- .../configuration/QualifiedParameters.ts | 22 +++---- packages/fast-check/src/fast-check-default.ts | 2 + .../fast-check/src/random/generator/Random.ts | 23 +++---- .../src/random/generator/RandomGenerator.ts | 64 +++++++++++++++++++ .../test/e2e/GenerateAllValues.spec.ts | 2 +- .../test/e2e/NoStackOverflowOnShrink.spec.ts | 2 +- .../test/e2e/ReplayCommands.spec.ts | 2 +- .../__test-helpers__/ArbitraryAssertions.ts | 2 +- .../__test-helpers__/RandomHelpers.ts | 3 +- .../_internals/ArrayArbitrary.spec.ts | 2 +- .../test/unit/arbitrary/commands.spec.ts | 2 +- .../test/unit/check/runner/Tosser.spec.ts | 2 +- .../configuration/QualifiedParameters.spec.ts | 8 +-- .../test/unit/random/generator/Random.spec.ts | 2 +- .../fast-check/test/unit/stubs/generators.ts | 34 ++-------- pnpm-lock.yaml | 13 ++-- 23 files changed, 137 insertions(+), 92 deletions(-) create mode 100644 .changeset/old-cobras-teach.md create mode 100644 packages/fast-check/src/random/generator/RandomGenerator.ts diff --git a/.changeset/old-cobras-teach.md b/.changeset/old-cobras-teach.md new file mode 100644 index 00000000..6e24fef7 --- /dev/null +++ b/.changeset/old-cobras-teach.md @@ -0,0 +1,5 @@ +--- +"fast-check": patch +--- + +⚡️ Bump pure-rand to v8 diff --git a/examples/003-misc/mazeGenerator/src/mazeGenerator.ts b/examples/003-misc/mazeGenerator/src/mazeGenerator.ts index dbba99cb..eb8f29a6 100644 --- a/examples/003-misc/mazeGenerator/src/mazeGenerator.ts +++ b/examples/003-misc/mazeGenerator/src/mazeGenerator.ts @@ -1,5 +1,5 @@ // Implementation inspired from https://github.com/dubzzz/various-algorithms/blob/main/algorithms/graph/maze-generator/implem.cpp -import { xorshift128plus } from 'pure-rand/generator/XorShift'; +import { xorshift128plus } from 'pure-rand/generator/xorshift128plus'; import { Random } from 'fast-check'; export type Dimension = { diff --git a/examples/package.json b/examples/package.json index f7ae6aba..a4bca632 100644 --- a/examples/package.json +++ b/examples/package.json @@ -19,7 +19,7 @@ "fast-check": "workspace:*", "happy-dom": "^20.8.3", "lodash": "^4.17.23", - "pure-rand": "^7.0.1", + "pure-rand": "^8.0.0", "react": "^19.2.4", "react-dom": "^19.2.4", "supertest": "^7.2.2", diff --git a/packages/fast-check/README.md b/packages/fast-check/README.md index 5218ea5c..9467bd80 100644 --- a/packages/fast-check/README.md +++ b/packages/fast-check/README.md @@ -115,21 +115,20 @@ It also proved useful in finding bugs among major open source projects such as [ Here are the minimal requirements to use fast-check properly without any polyfills: -| fast-check | node | ECMAScript version | _TypeScript (optional)_ | -| ---------- | ------------------------------------ | ------------------ | ----------------------- | -| **4.x** | ≥12.20.0(1)(2) | ES2020 | ≥5.0 | -| **3.x** | ≥8(3) | ES2017 | ≥4.1(4) | -| **2.x** | ≥8(3) | ES2017 | ≥3.2(5) | -| **1.x** | ≥0.12(3) | ES3 | ≥3.0(5) | +| fast-check | node | ECMAScript version | _TypeScript (optional)_ | +| ---------- | ---------------------- | ------------------ | ----------------------- | +| **4.x** | ≥12.17.0(1) | ES2020 | ≥5.0 | +| **3.x** | ≥8(2) | ES2017 | ≥4.1(3) | +| **2.x** | ≥8(2) | ES2017 | ≥3.2(4) | +| **1.x** | ≥0.12(2) | ES3 | ≥3.0(4) |
More details... 1. Even if version 12.x should support most of the ES2020 features that will be leveraged by the version 4, we recommend relying at least on version 14.x of Node as it supports all the targeted specification. In addition, we highly encourage switching to still supported LTS versions of Node and not sticking to unsupported versions for too long. -2. Starting at 4.6.0 we require at least the version 12.20.0 of node, while we used to consider 12.17.0 as good enough until now. We agreed to introduce this breaking change outside of a major release given it only implies moving to a more recent release of the 12.x without having to switch to another major of node. -3. Except for features that cannot be polyfilled - such as `bigint`-related ones - all the capabilities of fast-check should be usable given you use at least the minimal recommended version of node associated to your major of fast-check. -4. Require either lib or target ≥ ES2020 or `@types/node` to be installed. -5. Require either lib or target ≥ ES2015 or `@types/node` to be installed. +2. Except for features that cannot be polyfilled - such as `bigint`-related ones - all the capabilities of fast-check should be usable given you use at least the minimal recommended version of node associated to your major of fast-check. +3. Require either lib or target ≥ ES2020 or `@types/node` to be installed. +4. Require either lib or target ≥ ES2015 or `@types/node` to be installed.
diff --git a/packages/fast-check/package.json b/packages/fast-check/package.json index d0cb2942..9c6bf553 100644 --- a/packages/fast-check/package.json +++ b/packages/fast-check/package.json @@ -38,7 +38,7 @@ "build-ci": "rolldown -c && pnpm run build:post-build", "typecheck": "tsc --noEmit", "test-bundle": "for f in test-bundle/*.mjs test-bundle/*.cjs; do [ -f \"$f\" ] && echo \"Running ${f##*/}\" && node \"$f\" || exit 1; done", - "test-legacy-bundle": "nvs add 12.20.0 && for f in test-bundle/*.cjs; do [ -f \"$f\" ] && echo \"Running ${f##*/}\" && $(nvs which 12.20.0) \"$f\" || exit 1; done", + "test-legacy-bundle": "nvs add 12.17.0 && for f in test-bundle/*.cjs; do [ -f \"$f\" ] && echo \"Running ${f##*/}\" && $(nvs which 12.17.0) \"$f\" || exit 1; done", "docs": "api-extractor run --local && rm docs/fast-check.api.json && typedoc --out docs src/fast-check-default.ts", "docs-ci": "cross-env EXPECT_GITHUB_SHA=true pnpm run docs", "docs:serve": "pnpm run dlx serve docs/" @@ -55,10 +55,10 @@ }, "homepage": "https://fast-check.dev/", "engines": { - "node": ">=12.20.0" + "node": ">=12.17.0" }, "dependencies": { - "pure-rand": "^7.0.1" + "pure-rand": "^8.0.0" }, "devDependencies": { "@fast-check/poisoning": "workspace:*", diff --git a/packages/fast-check/src/check/runner/Tosser.ts b/packages/fast-check/src/check/runner/Tosser.ts index 60e8a3c7..beb9c53c 100644 --- a/packages/fast-check/src/check/runner/Tosser.ts +++ b/packages/fast-check/src/check/runner/Tosser.ts @@ -1,18 +1,18 @@ import type { RandomGenerator } from 'pure-rand/types/RandomGenerator'; -import { skipN } from 'pure-rand/distribution/SkipN'; import { Random } from '../../random/generator/Random.js'; import type { IRawProperty } from '../property/IRawProperty.js'; import { Value } from '../arbitrary/definition/Value.js'; import { safeMap } from '../../utils/globals.js'; import type { QualifiedRandomGenerator } from './configuration/QualifiedParameters.js'; +import { adaptRandomGenerator } from '../../random/generator/RandomGenerator.js'; /** * Extracting tossNext out of toss was dropping some bailout reasons on v8 side * @internal */ function tossNext(generator: IRawProperty, rng: QualifiedRandomGenerator, index: number): Value { - rng.unsafeJump(); + rng.jump(); return generator.generate(new Random(rng), index); } @@ -45,9 +45,9 @@ export function* lazyToss( ): IterableIterator<() => Value> { yield* safeMap(examples, (e) => () => new Value(e, undefined)); let idx = 0; - let rng = random(seed); + const rng = adaptRandomGenerator(random(seed)); for (;;) { - rng = rng.jump ? rng.jump() : skipN(rng, 42); + rng.jump(); yield lazyGenerate(generator, rng, idx++); } } diff --git a/packages/fast-check/src/check/runner/configuration/Parameters.ts b/packages/fast-check/src/check/runner/configuration/Parameters.ts index d4ba1e38..d9a32c62 100644 --- a/packages/fast-check/src/check/runner/configuration/Parameters.ts +++ b/packages/fast-check/src/check/runner/configuration/Parameters.ts @@ -1,7 +1,7 @@ import type { RandomType } from './RandomType.js'; import type { VerbosityLevel } from './VerbosityLevel.js'; import type { RunDetails } from '../reporter/RunDetails.js'; -import type { RandomGenerator } from 'pure-rand/types/RandomGenerator'; +import type { RandomGenerator } from '../../../random/generator/RandomGenerator.js'; /** * Customization of the parameters used to run the properties diff --git a/packages/fast-check/src/check/runner/configuration/QualifiedParameters.ts b/packages/fast-check/src/check/runner/configuration/QualifiedParameters.ts index bfb0211c..532f51f6 100644 --- a/packages/fast-check/src/check/runner/configuration/QualifiedParameters.ts +++ b/packages/fast-check/src/check/runner/configuration/QualifiedParameters.ts @@ -1,19 +1,20 @@ import type { Parameters } from './Parameters.js'; import { VerbosityLevel } from './VerbosityLevel.js'; import type { RunDetails } from '../reporter/RunDetails.js'; -import type { RandomGenerator } from 'pure-rand/types/RandomGenerator'; -import { unsafeSkipN } from 'pure-rand/distribution/UnsafeSkipN'; -import { congruential32 } from 'pure-rand/generator/LinearCongruential'; -import { mersenne } from 'pure-rand/generator/MersenneTwister'; -import { xorshift128plus } from 'pure-rand/generator/XorShift'; -import { xoroshiro128plus } from 'pure-rand/generator/XoroShiro'; +import { congruential32 } from 'pure-rand/generator/congruential32'; +import { mersenne } from 'pure-rand/generator/mersenne'; +import { xorshift128plus } from 'pure-rand/generator/xorshift128plus'; +import { xoroshiro128plus } from 'pure-rand/generator/xoroshiro128plus'; +import { adaptRandomGenerator } from '../../../random/generator/RandomGenerator.js'; + +import type { RandomGenerator, RandomGeneratorInternal } from '../../../random/generator/RandomGenerator.js'; const safeDateNow = Date.now; const safeMathMin = Math.min; const safeMathRandom = Math.random; /** @internal */ -export type QualifiedRandomGenerator = RandomGenerator & Required>; +export type QualifiedRandomGenerator = RandomGeneratorInternal; /** * Configuration extracted from incoming Parameters @@ -104,10 +105,7 @@ function createQualifiedRandomGenerator( ): (seed: number) => QualifiedRandomGenerator { return (seed) => { const rng = random(seed); - if (rng.unsafeJump === undefined) { - rng.unsafeJump = () => unsafeSkipN(rng, 42); - } - return rng as QualifiedRandomGenerator; + return adaptRandomGenerator(rng); }; } @@ -150,7 +148,7 @@ function readRandomType(p: Parameters): (seed: number) => QualifiedRandomG if ('max' in mrng && mrng.max !== 0x7fffffff) { throw new Error(`Invalid random number generator: max must equal 0x7fffffff, got ${String(mrng.max)}`); } - if ('unsafeJump' in mrng) { + if (mrng === adaptRandomGenerator(mrng)) { return p.randomType as (seed: number) => QualifiedRandomGenerator; } return createQualifiedRandomGenerator(p.randomType); diff --git a/packages/fast-check/src/fast-check-default.ts b/packages/fast-check/src/fast-check-default.ts index dc3a1488..f93e89d8 100644 --- a/packages/fast-check/src/fast-check-default.ts +++ b/packages/fast-check/src/fast-check-default.ts @@ -205,6 +205,7 @@ import { stringMatching } from './arbitrary/stringMatching.js'; import { noShrink } from './arbitrary/noShrink.js'; import { noBias } from './arbitrary/noBias.js'; import { limitShrink } from './arbitrary/limitShrink.js'; +import type { RandomGenerator } from './random/generator/RandomGenerator.js'; // Explicit cast into string to avoid to have __type: "process.env.__PACKAGE_TYPE__" /** @@ -326,6 +327,7 @@ export type { GlobalPropertyHookFunction, Parameters, RandomType, + RandomGenerator, ExecutionTree, RunDetails, RunDetailsFailureProperty, diff --git a/packages/fast-check/src/random/generator/Random.ts b/packages/fast-check/src/random/generator/Random.ts index 65af865c..cf9254f8 100644 --- a/packages/fast-check/src/random/generator/Random.ts +++ b/packages/fast-check/src/random/generator/Random.ts @@ -1,6 +1,7 @@ -import { unsafeUniformBigIntDistribution } from 'pure-rand/distribution/UnsafeUniformBigIntDistribution'; -import { unsafeUniformIntDistribution } from 'pure-rand/distribution/UnsafeUniformIntDistribution'; -import type { RandomGenerator } from 'pure-rand/types/RandomGenerator'; +import { uniformBigInt } from 'pure-rand/distribution/uniformBigInt'; +import { uniformInt } from 'pure-rand/distribution/uniformInt'; +import { adaptRandomGenerator } from './RandomGenerator.js'; +import type { RandomGenerator, RandomGeneratorInternal } from './RandomGenerator.js'; const MIN_INT: number = 0x80000000 | 0; const MAX_INT: number = 0x7fffffff | 0; @@ -15,14 +16,14 @@ const DBL_DIVISOR: number = Math.pow(2, -53); */ export class Random { /** @internal */ - private internalRng: RandomGenerator; + private internalRng: RandomGeneratorInternal; /** * Create a mutable random number generator by cloning the passed one and mutate it * @param sourceRng - Immutable random generator from pure-rand library, will not be altered (a clone will be) */ constructor(sourceRng: RandomGenerator) { - this.internalRng = sourceRng.clone(); + this.internalRng = adaptRandomGenerator(sourceRng.clone()); } /** @@ -37,7 +38,7 @@ export class Random { * @param bits - Number of bits to generate */ next(bits: number): number { - return unsafeUniformIntDistribution(0, (1 << bits) - 1, this.internalRng); + return uniformInt(this.internalRng, 0, (1 << bits) - 1); } /** @@ -45,7 +46,7 @@ export class Random { */ nextBoolean(): boolean { - return unsafeUniformIntDistribution(0, 1, this.internalRng) === 1; + return uniformInt(this.internalRng, 0, 1) === 1; } /** @@ -60,11 +61,7 @@ export class Random { */ nextInt(min: number, max: number): number; nextInt(min?: number, max?: number): number { - return unsafeUniformIntDistribution( - min === undefined ? MIN_INT : min, - max === undefined ? MAX_INT : max, - this.internalRng, - ); + return uniformInt(this.internalRng, min === undefined ? MIN_INT : min, max === undefined ? MAX_INT : max); } /** @@ -73,7 +70,7 @@ export class Random { * @param max - Maximal bigint value */ nextBigInt(min: bigint, max: bigint): bigint { - return unsafeUniformBigIntDistribution(min, max, this.internalRng); + return uniformBigInt(this.internalRng, min, max); } /** diff --git a/packages/fast-check/src/random/generator/RandomGenerator.ts b/packages/fast-check/src/random/generator/RandomGenerator.ts new file mode 100644 index 00000000..a4c09610 --- /dev/null +++ b/packages/fast-check/src/random/generator/RandomGenerator.ts @@ -0,0 +1,64 @@ +import type { RandomGenerator as RandomGenerator8x } from 'pure-rand/types/RandomGenerator'; +import type { JumpableRandomGenerator as JumpableRandomGenerator8x } from 'pure-rand/types/JumpableRandomGenerator'; +import { skipN } from 'pure-rand/utils/skipN'; + +interface RandomGenerator7x { + clone(): RandomGenerator7x; + next(): [number, RandomGenerator7x]; + jump?(): RandomGenerator7x; + unsafeNext(): number; + unsafeJump?(): void; + getState(): readonly number[]; +} + +/** + * Merged type supporting both pure-rand v7 and v8 random generators. + * Keeping compatibility with v7 avoids a breaking API change and a new major version. + * @remarks Since 4.6.0 + * @public + */ +export type RandomGenerator = RandomGenerator7x | RandomGenerator8x | JumpableRandomGenerator8x; + +/** @internal */ +export type RandomGeneratorInternal = JumpableRandomGenerator8x; + +/** @internal */ +function adaptRandomGeneratorTo8x(rng: RandomGenerator): RandomGenerator8x | JumpableRandomGenerator8x { + if ('unsafeNext' in rng) { + // 7.x generation + if (rng.unsafeJump === undefined) { + return { + clone: () => adaptRandomGeneratorTo8x(rng), + next: () => rng.unsafeNext(), + getState: () => rng.getState(), + }; + } + return { + clone: () => adaptRandomGeneratorTo8x(rng), + next: () => rng.unsafeNext(), + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + jump: () => rng.unsafeJump!(), + getState: () => rng.getState(), + }; + } + // 8.x generation + return rng; +} + +/** @internal */ +function adaptRandomGeneratorToInternal(rng: RandomGenerator8x | JumpableRandomGenerator8x): RandomGeneratorInternal { + if ('jump' in rng && typeof rng.jump === 'function') { + return rng; + } + return { + clone: () => adaptRandomGeneratorToInternal(rng), + next: () => rng.next(), + jump: () => skipN(rng, 42), + getState: () => rng.getState(), + }; +} + +/** @internal */ +export function adaptRandomGenerator(rng: RandomGenerator): RandomGeneratorInternal { + return adaptRandomGeneratorToInternal(adaptRandomGeneratorTo8x(rng)); +} diff --git a/packages/fast-check/test/e2e/GenerateAllValues.spec.ts b/packages/fast-check/test/e2e/GenerateAllValues.spec.ts index 44bb65b4..29835dc8 100644 --- a/packages/fast-check/test/e2e/GenerateAllValues.spec.ts +++ b/packages/fast-check/test/e2e/GenerateAllValues.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { xorshift128plus } from 'pure-rand/generator/XorShift'; +import { xorshift128plus } from 'pure-rand/generator/xorshift128plus'; import * as fc from '../../src/fast-check.js'; import { seed } from './seed.js'; diff --git a/packages/fast-check/test/e2e/NoStackOverflowOnShrink.spec.ts b/packages/fast-check/test/e2e/NoStackOverflowOnShrink.spec.ts index a23cb25e..ad1fd63d 100644 --- a/packages/fast-check/test/e2e/NoStackOverflowOnShrink.spec.ts +++ b/packages/fast-check/test/e2e/NoStackOverflowOnShrink.spec.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest'; -import { xorshift128plus } from 'pure-rand/generator/XorShift'; +import { xorshift128plus } from 'pure-rand/generator/xorshift128plus'; import * as fc from '../../src/fast-check.js'; import { seed } from './seed.js'; diff --git a/packages/fast-check/test/e2e/ReplayCommands.spec.ts b/packages/fast-check/test/e2e/ReplayCommands.spec.ts index 7bd548d7..e34e9655 100644 --- a/packages/fast-check/test/e2e/ReplayCommands.spec.ts +++ b/packages/fast-check/test/e2e/ReplayCommands.spec.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest'; -import { mersenne } from 'pure-rand/generator/MersenneTwister'; +import { mersenne } from 'pure-rand/generator/mersenne'; import * as fc from '../../src/fast-check.js'; import { seed } from './seed.js'; diff --git a/packages/fast-check/test/unit/arbitrary/__test-helpers__/ArbitraryAssertions.ts b/packages/fast-check/test/unit/arbitrary/__test-helpers__/ArbitraryAssertions.ts index 68d11391..6bb20c08 100644 --- a/packages/fast-check/test/unit/arbitrary/__test-helpers__/ArbitraryAssertions.ts +++ b/packages/fast-check/test/unit/arbitrary/__test-helpers__/ArbitraryAssertions.ts @@ -1,5 +1,5 @@ import { expect } from 'vitest'; -import { xorshift128plus } from 'pure-rand/generator/XorShift'; +import { xorshift128plus } from 'pure-rand/generator/xorshift128plus'; import * as fc from 'fast-check'; import { assertNoPoisoning, restoreGlobals } from '@fast-check/poisoning'; diff --git a/packages/fast-check/test/unit/arbitrary/__test-helpers__/RandomHelpers.ts b/packages/fast-check/test/unit/arbitrary/__test-helpers__/RandomHelpers.ts index 6f332b0f..3e955b6e 100644 --- a/packages/fast-check/test/unit/arbitrary/__test-helpers__/RandomHelpers.ts +++ b/packages/fast-check/test/unit/arbitrary/__test-helpers__/RandomHelpers.ts @@ -21,6 +21,7 @@ export function fakeRandom(): { instance: Random } & Omit, ' // Calling `new MyRandom` triggers a call to the default ctor of `Random`. // As we don't use anything from this base class, we just pass the ctor with a value that looks ok for it. - const instance = new MyRandom({ clone: () => null } as any); + const buildInternal = () => ({ clone: () => buildInternal() }); + const instance = new MyRandom(buildInternal() as any); return { instance, clone, next, nextBoolean, nextInt, nextBigInt, nextDouble, getState }; } diff --git a/packages/fast-check/test/unit/arbitrary/_internals/ArrayArbitrary.spec.ts b/packages/fast-check/test/unit/arbitrary/_internals/ArrayArbitrary.spec.ts index 25e804d9..c5f9affc 100644 --- a/packages/fast-check/test/unit/arbitrary/_internals/ArrayArbitrary.spec.ts +++ b/packages/fast-check/test/unit/arbitrary/_internals/ArrayArbitrary.spec.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi } from 'vitest'; import fc from 'fast-check'; -import { mersenne } from 'pure-rand/generator/MersenneTwister'; +import { mersenne } from 'pure-rand/generator/mersenne'; import { ArrayArbitrary } from '../../../../src/arbitrary/_internals/ArrayArbitrary.js'; import { Value } from '../../../../src/check/arbitrary/definition/Value.js'; diff --git a/packages/fast-check/test/unit/arbitrary/commands.spec.ts b/packages/fast-check/test/unit/arbitrary/commands.spec.ts index 08f3474d..0eec4a8a 100644 --- a/packages/fast-check/test/unit/arbitrary/commands.spec.ts +++ b/packages/fast-check/test/unit/arbitrary/commands.spec.ts @@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest'; import * as fc from 'fast-check'; import { commands } from '../../../src/arbitrary/commands.js'; -import { xorshift128plus } from 'pure-rand/generator/XorShift'; +import { xorshift128plus } from 'pure-rand/generator/xorshift128plus'; import type { Command } from '../../../src/check/model/command/Command.js'; import { Random } from '../../../src/random/generator/Random.js'; import { Arbitrary } from '../../../src/check/arbitrary/definition/Arbitrary.js'; diff --git a/packages/fast-check/test/unit/check/runner/Tosser.spec.ts b/packages/fast-check/test/unit/check/runner/Tosser.spec.ts index c4e993bc..a4f0ff7d 100644 --- a/packages/fast-check/test/unit/check/runner/Tosser.spec.ts +++ b/packages/fast-check/test/unit/check/runner/Tosser.spec.ts @@ -9,7 +9,7 @@ import type { Random } from '../../../../src/random/generator/Random.js'; import { Value } from '../../../../src/check/arbitrary/definition/Value.js'; import * as stubArb from '../../stubs/arbitraries.js'; -import { xorshift128plus } from 'pure-rand/generator/XorShift'; +import { xorshift128plus } from 'pure-rand/generator/xorshift128plus'; import type { QualifiedRandomGenerator } from '../../../../src/check/runner/configuration/QualifiedParameters.js'; const rngProducer = xorshift128plus as (seed: number) => QualifiedRandomGenerator; diff --git a/packages/fast-check/test/unit/check/runner/configuration/QualifiedParameters.spec.ts b/packages/fast-check/test/unit/check/runner/configuration/QualifiedParameters.spec.ts index f3f63025..c91b568e 100644 --- a/packages/fast-check/test/unit/check/runner/configuration/QualifiedParameters.spec.ts +++ b/packages/fast-check/test/unit/check/runner/configuration/QualifiedParameters.spec.ts @@ -1,9 +1,9 @@ import { describe, it, expect } from 'vitest'; import * as fc from 'fast-check'; -import { mersenne } from 'pure-rand/generator/MersenneTwister'; -import { congruential32 } from 'pure-rand/generator/LinearCongruential'; -import { xoroshiro128plus } from 'pure-rand/generator/XoroShiro'; -import { xorshift128plus } from 'pure-rand/generator/XorShift'; +import { mersenne } from 'pure-rand/generator/mersenne'; +import { congruential32 } from 'pure-rand/generator/congruential32'; +import { xoroshiro128plus } from 'pure-rand/generator/xoroshiro128plus'; +import { xorshift128plus } from 'pure-rand/generator/xorshift128plus'; import { read } from '../../../../../src/check/runner/configuration/QualifiedParameters.js'; import type { RandomType } from '../../../../../src/check/runner/configuration/RandomType.js'; diff --git a/packages/fast-check/test/unit/random/generator/Random.spec.ts b/packages/fast-check/test/unit/random/generator/Random.spec.ts index 2a455a9c..a1d60f82 100644 --- a/packages/fast-check/test/unit/random/generator/Random.spec.ts +++ b/packages/fast-check/test/unit/random/generator/Random.spec.ts @@ -1,5 +1,5 @@ import { describe, it } from 'vitest'; -import { xorshift128plus } from 'pure-rand/generator/XorShift'; +import { xorshift128plus } from 'pure-rand/generator/xorshift128plus'; import * as fc from 'fast-check'; import { Random } from '../../../../src/random/generator/Random.js'; diff --git a/packages/fast-check/test/unit/stubs/generators.ts b/packages/fast-check/test/unit/stubs/generators.ts index 612904ef..c3ebf664 100644 --- a/packages/fast-check/test/unit/stubs/generators.ts +++ b/packages/fast-check/test/unit/stubs/generators.ts @@ -11,16 +11,10 @@ class NoCallGenerator implements RandomGenerator { clone(): RandomGenerator { return this; } - next(): [number, RandomGenerator] { + next(): number { throw new Error('Method not implemented.'); } - unsafeNext(): number { - throw new Error('Method not implemented.'); - } - min(): number { - throw new Error('Method not implemented.'); - } - max(): number { + jump(): number { throw new Error('Method not implemented.'); } getState(): readonly number[] { @@ -44,12 +38,7 @@ class FastIncreaseRandomGenerator implements RandomGenerator { clone(): RandomGenerator { return new FastIncreaseRandomGenerator(this.value, this.incr); } - next(): [number, RandomGenerator] { - // need to tweak incr in order to use a large range of values - // uniform distribution expects some entropy - return [this.value, new FastIncreaseRandomGenerator((this.value + this.incr) | 0, 2 * this.incr + 1)]; - } - unsafeNext(): number { + next(): number { // need to tweak incr in order to use a large range of values // uniform distribution expects some entropy const out = this.value; @@ -57,12 +46,6 @@ class FastIncreaseRandomGenerator implements RandomGenerator { this.incr = 2 * this.incr + 1; return out; } - min(): number { - return -0x80000000; - } - max(): number { - return 0x7fffffff; - } getState(): readonly number[] { throw new Error('Method not implemented.'); } @@ -82,20 +65,11 @@ class CounterRandomGenerator implements RandomGenerator { clone(): RandomGenerator { return new CounterRandomGenerator(this.value); } - next(): [number, RandomGenerator] { - return [this.value, new CounterRandomGenerator((this.value + 1) | 0)]; - } - unsafeNext(): number { + next(): number { const out = this.value; this.value = (this.value + 1) | 0; return out; } - min(): number { - return -0x80000000; - } - max(): number { - return 0x7fffffff; - } getState(): readonly number[] { throw new Error('Method not implemented.'); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bfc0e482..1e679312 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -99,8 +99,8 @@ importers: specifier: ^4.17.23 version: 4.17.23 pure-rand: - specifier: ^7.0.1 - version: 7.0.1 + specifier: ^8.0.0 + version: 8.0.0 react: specifier: ^19.2.4 version: 19.2.4 @@ -154,8 +154,8 @@ importers: packages/fast-check: dependencies: pure-rand: - specifier: ^7.0.1 - version: 7.0.1 + specifier: ^8.0.0 + version: 8.0.0 devDependencies: '@fast-check/poisoning': specifier: workspace:* @@ -8570,6 +8570,9 @@ packages: pure-rand@7.0.1: resolution: {integrity: sha512-oTUZM/NAZS8p7ANR3SHh30kXB+zK2r2BPcEn/awJIbOvq82WoMN4p62AWWp3Hhw50G0xMsw1mhIBLqHw64EcNQ==} + pure-rand@8.0.0: + resolution: {integrity: sha512-7rgWlxG2gAvFPIQfUreo1XYlNvrQ9VnQPFWdncPkdl3icucLK0InOxsaafbvxGTnI6Bk/Rxmslg0lQlRCuzOXw==} + pvtsutils@1.3.6: resolution: {integrity: sha512-PLgQXQ6H2FWCaeRak8vvk1GW462lMxB5s3Jm673N82zI4vqtVUPuZdffdZbPDFRoU8kAhItWFtPCWiPpp4/EDg==} @@ -20674,6 +20677,8 @@ snapshots: pure-rand@7.0.1: {} + pure-rand@8.0.0: {} + pvtsutils@1.3.6: dependencies: tslib: 2.8.1 -- 2.51.2